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

how can i make a speed powerup?

Asked by 5 years ago

here is the script i tried (its in a part in workspace)

script.Parent.Touched:Connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") then
    p.Parent.Humanoid.WalkSpeed = 25
    script.Parent.Transparency = 1
    script.Parent.Script.Disabled = true
    wait(5)
    script.Parent.Transparency = 0
    script.Parent.Script.Disabled = false
    p.Parent.Humanoid.WalkSpeed = 16
end)

i disable the script so it cant be used while its invisible

thanks in advance

0
don't you also think that disabling the script also means, you can't use the script for anything else, thus also not running lines 6 through 10 theking48989987 2147 — 5y
0
also, why bother with script.Parent.script, if you want to disable the script , just do script.Disabled = true theking48989987 2147 — 5y
0
I think he might be referring to a different script inside the same block when he does that, but I don't know. Knineteen19 307 — 5y

1 answer

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

When you disable the script, you cannot enable it from the same script again, what you can do though to make it act like that is, use a debounce or a boolean to indicate weather you should change the speed or not like this:

local IsInvisible = false
script.Parent.Touched:Connect(function(p)
    if IsInvisible == false then
        if p.Parent:FindFirstChild("Humanoid") then
        p.Parent.Humanoid.WalkSpeed = 25
        script.Parent.Transparency = 1
        IsInvisible = true
    else
         wait(5)
        script.Parent.Transparency = 0
            p.Parent.Humanoid.WalkSpeed = 16
        IsInvisible = false
    end
end
end)

You are also missing an "end" for the if statement.

You could also check if the transparency is 1 then run code otherwise, run other code... But I feel using debounce is more easier to use..

Oh and by the way, there is no point in saying script.Parent.script.Disabled = true......... script.Disabled = true is the same thing.

Ad

Answer this question