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

Only half of this script runs more than once for some reason?

Asked by
Scerzy 85
8 years ago

So this script should only activate once per life, at the touch of a button.

local pressed=false
local b = Instance.new("BodyForce") 
script.Parent.Head.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not hit.Parent.Torso:findFirstChild(b) and pressed==false and script.Parent.Parent.Parent.Owner.Value==player  then
        pressed=true
        b.Force = Vector3.new(0,3500,0) 
        b.Parent = hit.Parent.Torso
        script.Parent.Head.BrickColor = BrickColor.new("Really black")
        wait(1)
        script.Parent.Head.BrickColor = BrickColor.new("Bright blue")
        wait(1)
        pressed=false
end
end)

Now I know it works because there's only one BodyForce within the torso and it doesn't duplicate when I press on the button more than once, but for some reason the button still changes colors from blue to black and back to blue again.

I have another button with the same concept but it works as it should and the button doesn't change color again

local pressed=false
script.Parent.Head.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local h = hit.Parent:findFirstChild("Humanoid")
    if pressed==false and script.Parent.Parent.Parent.Owner.Value==player and h.WalkSpeed==16  then
        h.WalkSpeed=25
        script.Parent.Head.BrickColor = BrickColor.new("Really black")
        wait(1)
        script.Parent.Head.BrickColor = BrickColor.new("Bright blue")
        wait(1)
        pressed=false

end
end)

I can't seem to find the problem with the first script. Thanks for the help.

Answer this question