So I have made a bedframe model and I want to make it change color when the click detector is clicked. I have a RemoteEvent labeled "Event" in my workspace, with a Script inside it. I have a LocalScript in StarterGUI connected to the event. I cannot get it to work and it is getting annoying, any ideas?
Code in the StarterGUI:
local clickdetector = game.Workspace.Bedframe.Pinecone.ClickDetector clickdetector.MouseClick:Connect(function() game.Workspace.Event:FireServer() end)
Code in the RemoteEvent (Event):
game.Workspace.Event.OnServerEvent:Connect(function() game.Workspace.Bedframe.Change.BrickColor="Pine Cone" end)
You don't need to use remote events with click detectors, just use the .MouseClick
event from your detector in your server script like this:
Update: Since game.Workspace.Bedframe.Change
is a model, we can't call .BrickColor
directly on it, we have to loop through its children and change said property on each of them.
Update2: Change 'waitTime' to the number of seconds you want your parts to stay painted.
local clickdetector = game.Workspace.Bedframe.Pinecone.ClickDetector local enabled = true local waitTime = 5 local color = "Pine Cone" local origColor = "Buttermilk" clickdetector.MouseClick:Connect(function(player) if enabled then enabled = false for i, part in pairs(game.Workspace.Bedframe.Change:GetDescendants()) do if part:IsA("BasePart") then part.BrickColor = BrickColor.new(color) end end wait(waitTime) for i, part in pairs(game.Workspace.Bedframe.Change:GetDescendants()) do if part:IsA("BasePart") then part.BrickColor = BrickColor.new(origColor) end end enabled = true end end)