I am trying to make a script that detects when the tree is broken/Health = 0 it drops items.
But it keeps saying " Workspace.Objects.Tree.Script:7: attempt to index number with ‘Changed’" and it won’t sense the change in the intValue of the health.
local tree = script.Parent
local Health = tree:WaitForChild("Health").Value
local MaxHealth = 5
local drop1 = game.ReplicatedStorage.Items.Log
local drop2 = game.ReplicatedStorage.Items.Leaves
Health.Changed:Connect(function()
print("Changed")
if Health <= 0 then
tree.Parent = game.ReplicatedStorage.BrokenObjects
Health = MaxHealth
wait(180)
tree.Parent = game.Workspace.Objects
local clone1 = drop1:Clone()
clone1.Parent = game.Workspace
clone1.Position = tree.Position
local clone2 = drop1:Clone()
clone2.Parent = game.Workspace
clone2.Position = tree.Position
local clone3 = drop2:Clone()
clone3.Parent = game.Workspace
clone3.Position = tree.Position
end
wait()
end)
Originally the variable named “Health” was grabbing the value of the IntValue instance (which is a number value) instead you wanted the variable to point to the IntValue instance itself as opposed to its stored value.
It still just doesn’t do anything. The health goes to 0 and it just sits there, no errors. It doesn’t print Changed so it just doesn’t detect the change.
That is one of the valid locations for a local script so it is being ran, you can always test if a local script is being ran by adding a print("some text here") line to the top of the script.
Use the server/client button in Studio to check this. You’ll see if the health value is changing on one vs the other environment. If this is the problem you’ll probably need a remote event.