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

I have a problem when getting a player from character, How to fix it?

I want to change player leaderstats when touching part and error error code:

09:29:18.457 - Workspace.Finish.Part.Script:4: attempt to perform arithmetic (add) on userdata and number

09:29:18.459 - Stack Begin

09:29:18.460 - Script 'Workspace.Finish.Part.Script', Line 4

09:29:18.461 - Stack End

This is the script:

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		player.leaderstats.Finish = player.leaderstats.Finish + 1
		player.data.cash = player.data.cash + 50
	end
end)

1 answer

✓ Accepted answer

Easy quick fix! Add .Value to access its value!

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        player.leaderstats.Finish.Value = player.leaderstats.Finish.Value + 1
        player.data.cash.Value = player.data.cash.Value + 50
    end
end)

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