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

How do I make a ontouched only happen once?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
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

0
Nah that didn't work TheBlue_Hood -5 — 6y
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 MmC00KIESmM 5 — 6y
0
The above code is correct aside from needing to set debounce to true after line 5. climethestair 1663 — 6y
Ad

Answer this question