Whenever a player goes to buy a sword. The shop fires a value of what sword and what player it is and sends it to a server script that then is supposed to give them a sword. Instead it gives it to every player online.
Local Script
local SwordGive = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("SwordGive")
local ReqGold = 10 -- Purchase Amount Here
local AvGold = game.Players.LocalPlayer.leaderboard.Gold --This is the player leaderboard stat for gold
local Rs = game.ReplicatedStorage.swords
script.Parent.MouseButton1Click:Connect(function()
if AvGold.Value >= ReqGold then
AvGold.Value = math.abs(AvGold.Value - ReqGold)
SwordGive:FireServer("Poop")
end
end)
Server Script
local SwordGive = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("SwordGive")
local Swords = game:GetService("ReplicatedStorage"):WaitForChild("swords")
game.Players.PlayerAdded:Connect(function(player)
SwordGive.OnServerEvent:Connect(function(plr, x)
local backpack = game.Players[player.Name].Backpack
print(player.Name)
print(game.Players)
if x == "Poop" then
local sword = Swords:WaitForChild("PoopSword")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
elseif x == "Stone" then
local sword = Swords:WaitForChild("StoneSword")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
elseif x == "Iron" then
local sword = Swords:WaitForChild("IronSword")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
elseif x == "Gold" then
local sword = Swords:WaitForChild("GoldSword")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
elseif x == "CastIron" then
local sword = Swords:WaitForChild("CastIronSword")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
elseif x == "LRed" then
local sword = Swords:WaitForChild("LHealingPotion")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
elseif x == "Speed" then
local sword = Swords:WaitForChild("SpeedPotion")
local swordcopy = sword:Clone()
swordcopy.Parent = backpack
end
end)
end)

1 comment
Thanks so much