Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Color changing script isn't working properly?

Asked by 4 years ago

It's a server script inside of a MeshPart in the player, it uses RemoteEvents that are called by a LocalScript in the PlayerGui

The LocalScript is in a colour palette gui which constantly updates a Color3 value in PlayerGui and then fires the RemoteEvent which the part then picks up, the problem is it uses the numbers that the Color3 value initially had when the player spawned and not using the updated ones, but if I use the exact same code in a LocalScript (replacing the stuff about the Events with a while true do loop) it works perfectly fine and updates the color with the new Color3 value

This is the script in the MeshPart:

game.ReplicatedStorage:FindFirstChild(script.Parent.Parent.Parent.Name).Colour.OnServerEvent:Connect(function()
    game.Players:WaitForChild(script.Parent.Parent.Parent.Name)
Ply = game.Players:FindFirstChild(script.Parent.Parent.Parent.Name)
PlyGui = Ply:FindFirstChild("PlayerGui")
Val = PlyGui:FindFirstChild("EnergyColor").Value
print("T")
    script.Parent.Color = Val
    print("Te")
end)

It prints everything as well and no errors come up in the Output console, what is the possible problem/ fix? I don't want to use a LocalScript because then the color changes will all be client-side only

1 answer

Log in to vote
0
Answered by
uhSaxlra 181
4 years ago

The server cannot read values that have been changed by the client, only be the server. The best way to combat this is send the server an argument instead of having it read the value.

game.ReplicatedStorage:FindFirstChild(script.Parent.Parent.Parent.Name).Colour.OnServerEvent:Connect(function(PlayerInstance,colorvalue)
    script.Parent.Color = colorvalue
end)
0
Click viewsource to get all of the script uhSaxlra 181 — 4y
Ad

Answer this question