I have a coin on which if you touch it, it should update a number value inside of my player, then destroy itself. But whenever the coin is touched by the player, it keeps saying "player is not a valid member of Players", I've tried printing the player and it says "jediplocoon", so why isn't this recognizing my username as a player? I'm really confused and if you could just point me in the right direction that would be great! Here's my code:
function OnTouched(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local player = hit.Parent
local Value = game.Players.player.PlayerGui.CoinGui.numcoins.Coins.Value
local num = math.random(1,3)
Value = Value + num
script.Parent:Destroy()
end
end
script.Parent.Touched:Connect(OnTouched)

2 comments
You also could use game.Players.LocalPlayer for localscripts.
You cannot run LocalScripts in workspace.