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

How to I make the material change?

Asked by 4 years ago
Edited 4 years ago

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)
0
workspace.Bedframe.Change.BrickColor = BrickColor.new("Pine Cone") greatneil80 2647 — 4y
0
Updated my answer, hopefully it works now Le_Teapots 913 — 4y
0
Updated my answer again Le_Teapots 913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
Hmm. Still does not work. If this helps, "Change" is a model with the parts I want colored. TotalElevation 45 — 4y
0
Oh, if its a model then it doesn't have the BrickColor property. Let me edit my code. Le_Teapots 913 — 4y
0
No problem! Glad to help :) Le_Teapots 913 — 4y
0
Actually sorry to pester you once more, but is there anyway I can make it wait and then change back to the original color? (Buttermilk) TotalElevation 45 — 4y
View all comments (3 more)
0
Thanks again! Thats all I need. Also, never knew you were the creator of a hit game! TotalElevation 45 — 4y
0
Oh and if you want to see it being used, join this game: https://www.roblox.com/games/3567225731/Model-Viewing TotalElevation 45 — 4y
0
I will gladly give it a look as soon as I can :) Le_Teapots 913 — 4y
Ad

Answer this question