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

How can I script a tool to be unusable while under a certain condition?

I've made a tool to recover the value of an IntValue (HungerVal.Value). However, I need this tool to only be usable when the player's thirst and hunger IntValues are above 0. The below code still lets me use the tool when either of those IntValues equal 0, when it should instead be unusable while that condition is true.

local food = script.Parent
local plr = game.Players.LocalPlayer
local HungerVal = plr:WaitForChild("HungerVal")
local ThirstVal = plr:WaitForChild("ThirstVal")
local used = false

food.Activated:connect(function()

	if HungerVal.Value and ThirstVal.Value > 0 then
		HungerVal.Value = HungerVal.Value + 40
		used = true

		if HungerVal.Value > 100 then
			HungerVal.Value = 100
		end

		food:Destroy()

	else
		print("I can't do that! I am unconcious!")
	end
end)

1 answer

✓ Accepted answer

The problem is that you are not checking HungerVal's Value. You are just checking if HungerVal.Value exist. so ofcource is gonna be true. So to fix this you would check both Values.

if HungerVal.Value > 0 and ThirstVal.Value > 0 then
	-- Code
end

2 comments

0

I see whats wrong now. Thanks.

0

Your welcome!

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