Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't my script let me index a IntValue?

Asked by
Faazo 84
5 years ago

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

1 answer

Log in to vote
1
Answered by
amanda 1059 Moderation Voter
5 years ago

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)
0
It works. Thank you! Faazo 84 — 5y
0
Glad to hear! amanda 1059 — 5y
Ad

Answer this question