How do I make a tool that increases your stat like in one of those simulators? The code I'm trying to use won't work. Here's the code.
holdername = nil;
script.Parent.Equipped:connect(function()
holdername = script.Parent.Parent.Name;
end)
script.Parent.Unequipped:connect(function()
holdername = nil;
end)
script.Parent.Activated:connect(function()
-- game.Players.holdername.leaderstats["Cheezburgers"].Value = game.Players.holdername.leaderstats["Cheezburgers"].Value + 1;
-- 14:33:38.767 - holdername is not a valid member of Players
-- Judging by this, I cannot detect a player by their name using a string variable/value.
end)
script.Parent.Deactivated:connect(function()
print(holdername.." ate a cheezburger!")
end)
Basically, it says that "holdername is not a valid member of Players" because there is no player named holdername, resulting in a error while it was expected to actually find a player with that name stored in the string variable/value to look into them to increase their stats. However, the expected part wasen't supported/able to work because it doesn't have that functionality, meaning I'll have to find a other way. Can someone help? Thanks.
If the stat handler script code is required, it is
game.Players.PlayerAdded:connect(function(player)
leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats";
cheezburgers = Instance.new("IntValue", leaderstats)
cheezburgers.Name = "Cheezburgers";
end)
The scripts mentioned in here are BY ME ONLY. This is also a solo project.

1 comment
I upvoted this because many people need to learn these things.