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

How can i re-enabled this script after a 4 secs?

Hi so ive got this little script that ive been working on

while wait(4.090) do
script.Disabled = true

function onTouch(part) 
	local humanoid = part.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then	
		humanoid.Health = 0	
		while wait(4.090) do
	end 
end

script.Parent.Touched:connect(onTouch)
end
end

this is used to make a "part" becoming deadly after 4.090 sec, what i want is that the part become deadly while like 2 sec and after it become passive, and after it wait again 4 sec to become deadly, i have a idea of what im trying to do here but need some help

5 comments

0

Can you use a code block? Also, what exactly do you mean?

0

I don't think your supposed to put the 'script.Disabled = true' part in a while loop

0

If you enable and disable scripts in your game it means you have bad code design. Look at what you need to do and how this cand be done in the code.

0

Code block is done and im trying to put countdown on those commands

0

The fact that you even have to disable the script in the first place is concerning. Very bad coding practices.

1 answer

This should change the way that it works. In a positive way.

local Disabled = false

script.Parent.Touched:Connect(function(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	
	if humanoid ~= nil and Disabled = false then   
		humanoid.Health = 0
		Disabled = true
		wait(2)
		Disabled = false
	else
		return
	end 
end

If the script disables itself, it won't run the rest of the script. Instead of disabling itself, it should set a variable to true, and while it's true, it can kill. While false, it does nothing.

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