#When Pressing button everybody gets 100 coins instead only 1 person

1 messages · Page 1 of 1 (latest)

potent garden
#

local DataStoreService = game:GetService("DataStoreService")
local PlayerInventory = DataStoreService:GetDataStore("PlayerInventory")
local PlayerCoins = DataStoreService:GetDataStore("PlayerInventory", "Coins")
local prompt = workspace.Button:WaitForChild("ProximityPrompt")

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats

local success, currentCoins = pcall(function()
    return PlayerCoins:GetAsync(player.UserId)
end)
if success then
    coins.Value = currentCoins or 0
    print("Success")
end

end)

local prompt = workspace.Button.ProximityPrompt

prompt.Triggered:Connect(function(player)
local coins = player:FindFirstChild("leaderstats") and
player.leaderstats:FindFirstChild("Coins")

local success, result = pcall(function()
    return PlayerCoins:IncrementAsync(player.UserId, 100)
end)

if success then
    coins.Value = result
end

end)

wild vigil
#

prompt.Triggered event returns the person who triggered it (geniously right?), so here is only one who pressed gets 100 coins. What do u mean by 'everybody gets 100'?

north flickerBOT
#

studio** You are now Level 1! **studio

potent garden
wild vigil
#

are these two images the same script?

potent garden
#

yes

#

its a bit long so i made two pictures

wild vigil
#

my brain is thinking rn why all players get them lol

#

o wait

#

I think I found

#

on this line: local PlayerCoins = DataStoreService:GetDataStore("PlayerInventory", "Coins"). does this "Coins" already means a key for DataStore? if ya so just all data saving on one key

#

try remove "Coins" and replace "PlayerInventory" fks on "PlayerCoins"