Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Color changing script isn't working properly?

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

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)

1 comment

0

Click viewsource to get all of the script

This discussion is preserved as it was. New answers, comments, and votes are closed.