Trouble With Filtering

Im making a game where the player is in a marble, i have made a GUI that changes a StringValue, When the string value changes, the players marble color will also change, it works great, Only problem is when the players marble color changes, the other players cant see that it changed,

Here is the script inside the GUI,

local Plr = game.Players.LocalPlayer
local ColorHolder = Plr:WaitForChild("ColorHolder")
local Color = ColorHolder.Color
local Button = script.Parent

Button.MouseButton1Up:Connect(function()
	
Color.Value = "Red"
	
end)

Now Here is the script in StarterPlayerScripts,

local ColorHolder = Plr:WaitForChild("ColorHolder")
local Color = ColorHolder.Color
local Character = Plr.Character
local Ball = Character:WaitForChild("Part")

while true do
	wait()
	
	if Color.Value == "Red" then
		Ball.BrickColor =  BrickColor.new("Really red")
	end
	
	if Color.Value == "Blue" then
		Ball.BrickColor =  BrickColor.new("Really blue")
	end
	
	if Color.Value == "Pink" then
		Ball.BrickColor =  BrickColor.new("Pink")
	end

Keep in mind they’re both Local Scripts,
And there’s a value in the player called “Color”

You need a remote event that tells server to change the string on other players devices as well in order for them to see red too

You have two problems in your system :

→ You can’t use game.Players.LocalPlayer in a script.

→ You use a LocalScript in StarterPlayerScripts, the changes are apply on client only.

Try to remake your system like that :

First, create a RemoteEvent in ReplicatedStorage, named “ChangeColor”.

image

Next, create a Script in ServerScriptServce, and put that :

game:GetService("ReplicatedStorage").ChangeColor.OnServerEvent:Connect(function(player, color)
	
	if color == "Red" then
		player.Character:WaitForChild("Part").BrickColor = BrickColor.new("Really red")	
	elseif color == "Blue" then
		player.Character:WaitForChild("Part").BrickColor = BrickColor.new("Really blue")	
	elseif color == "Pink" then
		player.Character:WaitForChild("Part").BrickColor = BrickColor.new("Pink")	
	end
	
end)

Next, in your button, create a LocalScript and write that:

script.Parent.MouseButton1Up:Connect(function()
	game:GetService("ReplicatedStorage").ChangeColor:FireServer("Red")
end)

After that, your change will be visible on all display.

1 Like