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

What is wrong with this script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") then local character = hit.Parent local plr = game.Players:GetPlayerFromCharacter(character) if plr then plr.PlayerGui.Hull.Value.Value = plr.PlayerGui.Hull.Value.Value +1 wait(5) end if plr.PlayerGui.Hull.Value.Value == 100 then script.Disable = true wait(5) script.Disabled = false end end end

script.Parent.Touched:connect(onTouched)

1
What exactly are you trying to do, and what is happening instead? Is there any output? Also, put your code in a code block (that little blue Lua symbol) Perci1 4988 — 9y
0
Don't use disabled to control scripts. It definitely doesn't make sense to disable the current one, since it won't be able to reactivate itself. BlueTaslem 18071 — 9y
0
I'm trying to make a counter that won't go above acertain value. ZarkValrain 0 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

You need to add 'debounce' so that the player cannot restore their Hull points by jumping on the part repeatedly. To prevent the Hull points from going beyond 100, just add an if statement that returns from the function if the Hull points are 100 or higher.

db = false
function onTouched(hit)
    if db then return end
    if hit.Parent:FindFirstChild("Humanoid") then 
        local character = hit.Parent 
        local plr = game.Players:GetPlayerFromCharacter(character) 
        if plr andplr.PlayerGui.Hull.Value.Value < 100 then
            db = true
            plr.PlayerGui.Hull.Value.Value = plr.PlayerGui.Hull.Value.Value +1
            wait(5)
            db = false
        end
    end
end

script.Parent.Touched:connect(onTouched)
Ad

Answer this question