I have a script that stops collecting fish when the max amount of fish has been reached. When I try to type fishinbackpack.Value
it says in the output Players.Faazo.PlayerGui.Max Fish Script:7: attempt to index field 'Value' (a number value)
I tried this on another script and it worked so i indexed it the same in this script as the other script. Why does this happen? fishinbackpack is an Intvalue. I tried changing it to a number value but the same thing happened. Here is the script
player = game.Players.LocalPlayer leaderstats = player:WaitForChild("leaderstats") fishinbackpack = leaderstats:WaitForChild("Fish in Backpack") MaxInt = player.PlayerGui:WaitForChild("MaxFishInt") MaxBool = player.PlayerGui:WaitForChild("MaxFishBool") fishinbackpack.Value.Changed:Connect(function() print("changed") if fishinbackpack.Value == MaxInt.Value then MaxBool.Value = true print("max") else print("not max") end end)
help greatly appreciated
The issue is that Changed
is an event for the IntValue
object, not for its Value
property.
To resolve this, simple remove .Value
in line 7.
player = game.Players.LocalPlayer leaderstats = player:WaitForChild("leaderstats") fishinbackpack = leaderstats:WaitForChild("Fish in Backpack") MaxInt = player.PlayerGui:WaitForChild("MaxFishInt") MaxBool = player.PlayerGui:WaitForChild("MaxFishBool") fishinbackpack.Changed:Connect(function() print("changed") if fishinbackpack.Value == MaxInt.Value then MaxBool.Value = true print("max") else print("not max") end end)