Hi,

I have this hunger script for a survival game I'm making.

I'm trying to change OnTouch to ClickDetector but can't seem to figure out how.

I appreciate any/all help, thanks in advance.

Here's the script:

local debounce = false

local theType = "Hunger" --Type to refill (Hunger or Thirst) local refillValue = 5 ----How much it refils when touched local waitTime = 100 --How many seconds till you can use it again

function onTouched(hit) if debounce == false then debounce = true local check = hit.Parent:FindFirstChild("Humanoid")

	if check ~= nil then
		local user = game.Players:GetPlayerFromCharacter(hit.Parent)
		if user ~= nil then
			local stats = user:findFirstChild("Stats")

			if stats ~= nil then 
				local type = stats:findFirstChild(theType) 
				
				if (type.Value + refillValue <= 100) then
					type.Value = type.Value + refillValue
				elseif (type.Value < 100) then
					type.Value = 100
				else
					return
				end

				script.Parent.Transparency = 1
				script.Parent.CanCollide = false
				wait(waitTime)
				script.Parent.CanCollide = false
				script.Parent.Transparency = 0

			end
		end
	end
	debounce = false
end

end script.Parent.Touched:connect(onTouched)

1 comment

0

Simply where it says onTouched change it to onClick