Railmints
|
  |
| Joined: 11 Aug 2014 |
| Total Posts: 272 |
|
|
| 01 Sep 2016 12:32 PM |
Right now i am trying to master remote events, and so i am developing a script where when you click on a part, its color changes to yellow. However, i do not know how to translate this script---
script.Parent.Activated:connect(function() if mouse.Target.ClassName == "Part" then mouse.Target.BrickColor = BrickColor.new(255, 255, 0) print(mouse.Target) end end)
from a local script to a regular script. How do i get the regular script to know what part was clicked on by the mouse? |
|
|
| Report Abuse |
|
|
Afro_Sub
|
  |
| Joined: 16 Jun 2013 |
| Total Posts: 1114 |
|
| |
|
pullman45
|
  |
| Joined: 09 Jul 2012 |
| Total Posts: 2891 |
|
|
| 01 Sep 2016 12:36 PM |
RemoteEvent:FireServer(mouse.Target)
In your ServerScript:
RemoteEvent.OnServerEvent:connect(function(player, MouseTarget) -- code end)
Do you need a further explanation? |
|
|
| Report Abuse |
|
|
pullman45
|
  |
| Joined: 09 Jul 2012 |
| Total Posts: 2891 |
|
|
| 01 Sep 2016 12:37 PM |
| It's a bit different for server to client. |
|
|
| Report Abuse |
|
|
Railmints
|
  |
| Joined: 11 Aug 2014 |
| Total Posts: 272 |
|
|
| 01 Sep 2016 12:47 PM |
| I get it now. You set mouse.Target as a parameter in the local script so the server script knows the value. Thats what i was struggling with, thanks! :) |
|
|
| Report Abuse |
|
|
pullman45
|
  |
| Joined: 09 Jul 2012 |
| Total Posts: 2891 |
|
|
| 01 Sep 2016 12:52 PM |
Here's how it's like for server to client:
Server- RemoteEvent:FireClient(player, stuff)
Client- RemoteEvent.OnClientEvent:connect(function(stuff) |
|
|
| Report Abuse |
|
|
Railmints
|
  |
| Joined: 11 Aug 2014 |
| Total Posts: 272 |
|
|
| 01 Sep 2016 12:54 PM |
The final scripts i have are here
Local script(inside of a tool)--
local player = game.Players.LocalPlayer local mouse = player:GetMouse()
script.Parent.Activated:connect(function() game.Workspace.color:FireServer(mouse.Target) end)
Server script(inside of workspace)
game.Workspace.color.OnServerEvent:connect(function(player, MouseTarget) if MouseTarget.ClassName == "Part" then MouseTarget.BrickColor = BrickColor.new(255,255,0) end end)
The Remote Event is named color and is also located inside of workspace |
|
|
| Report Abuse |
|
|
Railmints
|
  |
| Joined: 11 Aug 2014 |
| Total Posts: 272 |
|
|
| 01 Sep 2016 12:56 PM |
| Im wondering, would it be possible to communicate between client scripts as well? |
|
|
| Report Abuse |
|
|
pullman45
|
  |
| Joined: 09 Jul 2012 |
| Total Posts: 2891 |
|
|
| 01 Sep 2016 01:16 PM |
| I don't know if you're supposed to use them like this, but I think this is what BindableEvents/Functions are for. |
|
|
| Report Abuse |
|
|