Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how can i make a speed powerup?

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

3 comments

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

0

also, why bother with script.Parent.script, if you want to disable the script , just do script.Disabled = true

0

I think he might be referring to a different script inside the same block when he does that, but I don't know.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.