How do you make two parts change random() color

Hey so I’m having trouble having these skates change the same color when you step on the ice, how would I make that possible? Thanks for your time!

Script:

local Skate1 = game.ServerStorage.Items.Skate1
script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if not hit.Parent:FindFirstChild ("Skate1") then
			Skate1.Handle.BrickColor = BrickColor.Random()
			Skate1:Clone().Parent = hit.Parent 
		end
	end
end)

local Skate2 = game.ServerStorage.Items.Skate2
script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if not hit.Parent:FindFirstChild ("Skate2") then
			Skate2.Handle.BrickColor = BrickColor.Random()
			Skate2:Clone().Parent = hit.Parent 
		end
	end
end)

You need a variable in a shared scope which sets it to BrickColor.Random(), then coloring the parts with that variable, since you only called the function once and the brick color is what the function outputted.

1 Like

I kind of did this, although it’s the same color each time you go off and on.

local Skate1 = game.ServerStorage.Items.Skate1
local SetColor = BrickColor.Random()
script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if not hit.Parent:FindFirstChild ("Skate1") then
			Skate1.Handle.BrickColor = SetColor
			Skate1:Clone().Parent = hit.Parent 
		end
	end
end)

local Skate2 = game.ServerStorage.Items.Skate2
script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if not hit.Parent:FindFirstChild ("Skate2") then
			Skate2.Handle.BrickColor = SetColor
			Skate2:Clone().Parent = hit.Parent 
		end
	end
end)

Perhaps you want to set the variable to a new color again:
SetColor = BrickColor.Random()

Put this line somewhere after successfully coloring them. The new issue is how you should color both of them at the same time without their colors being different, a question of when to set it. A solution to this might be some rewriting that allows both skates to be worn at once instead of one at a time.

Well you could just make one function change both of them

local Skate2 = game.ServerStorage.Items.Skate2
local Skate1 = game.ServerStorage.Items.Skate1
script.Parent.Touched:Connect(function(hit)
        local SetColor = BrickColor.Random()
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if not hit.Parent:FindFirstChild ("Skate2") then
			Skate2.Handle.BrickColor = SetColor
			Skate2:Clone().Parent = hit.Parent 
            Skate1.Hand.e.BrickColor = SetColor
            Skate2:Clone.Parent = hit.Parent
		end
	end
end)
2 Likes