Sell system not working

This script is suppose to make it so when script.Parent touches sell it gives the player in team purple 20 coins and delete it self. The delete part works but the coins part doesn’t. I’ve tried a couple other methods and they still don’t work.

you have to remove the team.PlayerAdded:Connect(function(player) why are you checking if a player is added inside a Touched Event?
player = player.Name is pretty much why the player is not getting the coins.

Replace “player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 20” with:

player.leaderstats.Coins.Value += 20

What’s in the output?

oh ok thank you, but I tried all of that but the player still doesn’t get any coins.

All the players in purple team?

No, only one of them is in purple team.

you can get the player by

local player = game:GetPlayerFromCharacter(hit.Parent)

so your code will be like so

local s = script.Parent
s.Touched:Connect(function(hit)
if hit:IsA("BasePart") and hit.Name == "sell" then
for i,Player in pairs(game.Players:GetPlayers()) do
if Player.Team == game.Teams.purple then
Player.leaderstats.Coins.Value += 20
end
end
end
end)
1 Like

script.Parent never hits the player it hits the sell part.

alright then, updated my code.

omg thank you so much it worked.

1 Like