Hello! I am currently making a gun shop for my game where when you click it, you get your gun and you lose money; as if you were buying it in real life. I've been trying my best to fix, but it never worked. Here are the scripts.
local ToolNames = {"Shotgun"}
local Storage = game:GetService("ServerStorage")
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
function onPlayerEntered(newPlayer)
ClickDetector.MouseClick:connect(function(Player)
debounce = false
local stats = newPlayer.leaderstats
local cash = stats.Money
stats.Parent = newPlayer
if cash.Value >= 50 then
cash.Value = cash.Value - 50
wait(100)
game.Players.ChildAdded:connect(onPlayerEntered)
if Player and Player.Character then
local Backpack = Player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
Tool:clone().Parent = Backpack
end
end
end
end
end
