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

Brick colour change script isn't working?

Asked by
zomspi 541 Moderation Voter
5 years ago

My script to change the colour of a brick isn't working?

01game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
02    local stage = plr:WaitForChild("leaderstats"):WaitForChild("Stage")
03    stage.Changed:Connect(function()
04    if stage.Value >= 1 or script.Parent.Touched then
05        script.Parent.CanCollide = false
06        game.Workspace.Walls.Wall4.CanCollide = true
07        game.Workspace.Walls.Wall4.BrickColor = BrickColor.new("Really red")
08    end
09    end)
10    end)

3 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Events cannot be used as conditions, nor do they act like conditions.

Use a separate function for Touched, such as:

01game.Players.PlayerAdded:Connect(function()
02    script.Parent.Touched:Connect(function(hit)
03        if game.Players:GetPlayerFromCharacter(hit.Parent) then
04            if workspace:FindFirstChild("Wall4", true) then
05                local wall = workspace:FindFirstChild("Wall4", true)
06                wall.CanCollide = true
07                wall.BrickColor = BrickColor.new("Really red")
08            -- Your other function would go here
09            end
10        end
11    end)
12end)

Let me explain why you can't use events in conditional statements.

Events are RBXScriptSignals. RBXScriptSignals are signals that act like triggers for given functions; when they fire, a function is usually associated with it (unless you use Wait()). However, the main reason why they can't be used as conditions is because RBXScriptSignals don't return any values, they simply pass them. The difference is that passing a value means giving it to a function, and returning a value means that a function passes its own value to wherever it is called.

Ad
Log in to vote
0
Answered by 5 years ago

Uh maybe, just maybe this script will help you, the scripts on top is incorrect.

01game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
02        local stage = plr.leaderstats.Stage
03        stage.Changed:Connect(function()
04        if stage.Value >= 1 or script.Parent.Touched then
05            script.Parent.CanCollide = false
06            game.Workspace.Walls.Wall4.CanCollide = true
07            game.Workspace.Walls.Wall4.BrickColor = BrickColor.new("Really red")
08        end
09        end)
10        end)
Log in to vote
0
Answered by 5 years ago

so i can't really read the whole thing but:

01game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
02    local stage = plr:WaitForChild("leaderstats"):WaitForChild("Stage")
03    stage.Changed:Connect(function()
04    if stage.Value >= 1 or script.Parent.Touched then
05        script.Parent.CanCollide = false
06        game.Workspace.Walls.Wall4.CanCollide = true
07        game.Workspace.Walls.Wall4.BrickColor = BrickColor."Really red" --- that might be the problem,you should use . random
08    end
09    end)
10    end)
11 
12---make sure its anchored too.

Answer this question