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

What is wrong with this script?

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)

3 comments

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)

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.

0

I'm trying to make a counter that won't go above acertain value.

1 answer

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)

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