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

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

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

✓ Accepted answer

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)

2 comments

0

It works. Thank you!

0

Glad to hear!

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