Hey guys, I’m writing a script so that when I stand on a part it changes colour (there are two parts) but when i stand on ‘part1’… part2 changes colour I have read the script and i’m unable to see why. Also does anyone know how to script it so that it only changes colour WHILE the player is stood on it and it goes back to grey once they step off the part? Thanks a lot, here is my code:
What you did wrong is sending over boolean values over to the server without defining it. The server sees that you’re sending over the value true, what you could you is add two more arguments. ie. Task, Action.
game.ReplicatedStorage.RemoteFunction:InvokeServer("ChangeStart1", start1Ready) -- Do the Same for Start2
On the server, do not OnServerInvoke twice, rather make one, from the arguments we get from the client.
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player, Task, Action)
if Task == "ChangeStart1" then
if Action == true then
-- CHANGE START 1 BRICK COLOR HERE
elseif Action == false then
-- If you want to change it back or something
end
elseif Task == "ChangeStart2" then
if Action == true then
-- CHANGE START 2 BRICK COLOR HERE
elseif Action == false then
-- If you want to change it back or something
end
end
end
Adding to this, it may be better using a remote event rather than remote function if your simply changing the color on the server
(Ignore the ‘if start1Ready and start2Ready…’ part its just something i was going to add on later
Thank you so much, i’ve been trying to do this for two days, it was driving me mad lol, i really apretiate it, ill try out the script now and let you know if it works!
Oh also one last question, what do I put for the ‘task’ and ‘action’ that you put in your code?
Just leave that be or change it to anything you want since it’s a pseudo variable to relate back to the data given by the client (Local Script) therefore allowing you to change stuff on the server, if you want to change arguments, change it from the Client ( Local Script ) .
for Example on the Client( local script) you can do:
local Arg1 = "CAN PUT WHATEVER TASK YOU WANT HERE SO YOU CAN RELATE BACK TO IT ON THE SERVER"
local Arg2 = PUT ACTION HERE (true or false, strings, values, etc)
game.ReplicatedStorage.RemoteFunction:InvokeServer(Arg1, Arg2)
-- Arg1 is Task
-- Arg2 is Action
So essentially on the server, Task is referring to Arg1 (FROM CLIENT), and Action is referring to Arg2 (FROM CLIENT), You can name Task or Action to anything you want though
It’s because in the script in the second image, you’re replacing the first OnServerInvoke function with another.
OnServerInvoke isn’t an event like a RemoteEvent’s OnServerEvent, it’s a field that has a function as their value. So basically what your code is doing is replacing its original value with another value.
Try using 2 different RemoteFunctions instead of a single one