this script is supposed to charge a player 10 money to change their clothing however it charges every player in the server 10 money and changes their clothing too but if i use a localscript it would only make the new clothing visible to the player who bought it and wouldn't charge them any money
game.Players.PlayerAdded:Connect(function(player)
local clickDetector = script.Parent
script.Disabled = false
local function onMouseClick()
local oldchat = game.ReplicatedStorage.npcchatyesno:Clone()
oldchat.Parent = player.PlayerGui
local oldwalkspeed = player.Character:WaitForChild("Humanoid").WalkSpeed
local oldjumppower = player.Character:WaitForChild("Humanoid").JumpPower
player.Character:WaitForChild("Humanoid").WalkSpeed = 0
player.Character:WaitForChild("Humanoid").JumpPower = 0
local chatbox = player.PlayerGui.npcchatyesno
chatbox.Frame.TextBox.Text = "Would you like to buy the Assassin Rags for 10 rupees?"
chatbox.Frame.ButtonYes.Text = "Yes"
chatbox.Frame.ButtonNo.Text = "No"
chatbox.Frame.NPCName.Text = "Joseph"
local function yesbuttonPressed()
if player.PlayerRupees.Value >= 10 then
chatbox.Frame.ButtonYes:Destroy()
chatbox.Frame.ButtonNo:Destroy()
player.PlayerRupees.Value = player.PlayerRupees.Value - 10
player.ClothesValue.Value = "assassinrags"
player.Character.RogueShirt.ShirtTemplate = "http://www.roblox.com/asset/?id=2083053293"
player.Character.RoguePants.PantsTemplate = "http://www.roblox.com/asset/?id=2083054667"
chatbox.Frame.TextBox.Text = "Thank you for the purchase."
wait(1.5)
chatbox:Destroy()
player.Character.Humanoid.WalkSpeed = 22
player.Character.Humanoid.MaxHealth = 100
player.Character.Humanoid.Health = 100
player.Character:WaitForChild("Humanoid").JumpPower = oldjumppower
else
chatbox.Frame.ButtonYes:Destroy()
chatbox.Frame.ButtonNo:Destroy()
chatbox.Frame.TextBox.Text = "You don't have enough rupees for this."
wait(1.5)
chatbox:Destroy()
player.Character:WaitForChild("Humanoid").WalkSpeed = oldwalkspeed
player.Character:WaitForChild("Humanoid").JumpPower = oldjumppower
end
end
chatbox.Frame.ButtonYes.MouseButton1Down:connect(yesbuttonPressed)
local function nobuttonPressed()
player.Character:WaitForChild("Humanoid").WalkSpeed = oldwalkspeed
player.Character:WaitForChild("Humanoid").JumpPower = oldjumppower
chatbox:Destroy()
end
chatbox.Frame.ButtonNo.MouseButton1Down:connect(nobuttonPressed)
end
clickDetector.MouseClick:connect(onMouseClick)
end)

3 comments
Do you mind if you shortened the code and added frequent comments? Also if you have published the place, can you please link it? Thanks.
Try using a remoteevent, and have it fired by the client, and not the server.
https://www.roblox.com/games/4102346833/Rogue-Legacy here's the link