I have been making a game that uses values loaded in inside the player with instance.new, but when ever I try to change the value using a script I always get an error stating “Workspace.Part.ClickDetector.cashgive:6: attempt to index local ‘player’ (a nil value)”.
I have been looking across many sites to find a solution to this problem and have finally decided to write a post instead. How would I fix this? My apologies if this is a stupid question with an easy fix.
scripts used:
currency script:
game.Players.PlayerAdded:connect(function(player)
repeat wait() until player.Character
local stat = Instance.new("IntValue")
stat.Name = "UScurrency"
stat.Parent = player
end)
and cashgive script:
local player = game.Players.LocalPlayer
function GiveCash(player)
local USCash = player.Character.UScurrency.Value;
USCash = USCash + 5;
end;
player:WaitForChild("UScurrency").Changed:connect(function()
end)
script.Parent.MouseClick:connect(GiveCash);