Cannot check number value

so basically i want an axe to hit a tree(working), then a value attached to the tree goes += 1, then once that value hits 3, i want the tree to become uncollideable and play a sound and ish. that isnt working and i have no idea why.

local wood = script.Parent
local leaves = wood.Parent.leaves 
local hits = script.Parent.Hits
local hitsValue = hits.Value
local sound1 = wood.Sound1
local sounds = {sound1}
hits.Changed:Connect(function()
	print("checking hits")
	if hitsValue > 3 then
		print("--hits larger than 3--")
		sounds[math.random(1, #sounds)]:Play()
		wood.Anchored = false
		leaves.Anchored = false
		wait(2)
		wood.CanCollide = false
		leaves.CanCollide = false
	else
		print("uhhh")
	end
end)

(basically just checks whenever the value is updated (works perfectly) and checks if its larger than 3)

You’re setting the hitsValue variable to an integer, what you need to do is check Hits.Value in the Touched event.

local wood = script.Parent
local leaves = wood.Parent.leaves 
local hits = script.Parent.Hits
local sound1 = wood.Sound1
local sounds = {sound1}
hits.Changed:Connect(function()
   print("checking hits")
   if hits.Value > 3 then
   	print("--hits larger than 3--")
   	sounds[math.random(1, #sounds)]:Play()
   	wood.Anchored = false
   	leaves.Anchored = false
   	wait(2)
   	wood.CanCollide = false
   	leaves.CanCollide = false
   else
   	print("uhhh")
   end
end)

This should fix your issue :slight_smile:

1 Like

ohhhhh my gosh how did i not see that. ty dude

No worries :slight_smile: Glad to be able to help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.