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

How do I make a ontouched only happen once?

So here's my current code, I'm trying to make it happen only once and not again for that certain player but every time I do it either doesn't work or rapidly scales the character up

function onTouched(hit)
Character = hit.Parent
local ResizeData = ResizeModule.ScaleCharacter(Character,1.7, 
{ScaleTools = true, ScaleHats = true, ScaleBack = false})
ResizeData.StateChanged.Changed:connect(function(State) if not State then
Character.Humanoid.MaxHealth = 500
Character.Humanoid.WalkSpeed = 12 
Character.Humanoid.JumpPower = 100 
end wait(.1) Character.Humanoid.Health = Character.Humanoid.MaxHealth end) end
script.Parent.Touched:connect(onTouched)

1 answer

local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
	if debounce then return end
	Character = hit.Parent
	local ResizeData = ResizeModule.ScaleCharacter(Character,1.7,){ScaleTools = true, ScaleHats = true, ScaleBack = false})
	ResizeData.StateChanged.Changed:connect(function(State) 
	if not State then
		Character.Humanoid.MaxHealth = 500
		Character.Humanoid.WalkSpeed = 12
		Character.Humanoid.JumpPower = 100
	end 
	wait(.1) 
	Character.Humanoid.Health = Character.Humanoid.MaxHealth 
end)

try this

3 comments

0

Nah that didn't work

0

basically just add a debounce to your script, and then for it to not run for someone who already touched it all you have to do is if State then return end

0

The above code is correct aside from needing to set debounce to true after line 5.

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