Hey guys. Like it said in the title I wanna stop people from spamming the tools they already have. And there’s a shop system involved and i just have no idea where to put the code where it prevents ppl from spamming it
This is my script on serverscriptstorage
local buyToolEvent = game.ReplicatedStorage.buyTool
local function buyTool(player, tool)
if player.Character:FindFirstChild(tool.Name) then
return
end
if player.Backpack:FindFirstChild(tool.Name) then
return
end
if player.leaderstats.Gold.Value >= tool.Price.Value then
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - tool.Price.Value
local giveTool = game.ReplicatedStorage.ShopItems[tool.Name]:Clone()
giveTool.Parent = player.Backpack
end
end
buyToolEvent.OnServerEvent:Connect(buyTool)
and this is my script on the shop
local open = workspace.openPart
local frame = script.Parent
local closeButton = frame.closeButton
local buy1 = frame.buyButton1
local buy2 = frame.buyButton2
local buy3 = frame.buyButton3
local buyToolEvent = game.ReplicatedStorage.buyTool
local db = false
local dbTime = 2
frame.Visible = false
local function shopMenu(otherPart)
if not db then
db = true
local plr = game.Players:FindFirstChild(otherPart.Parent.Name)
if plr then
frame.Visible = true
plr.Character.Humanoid.WalkSpeed = 0
end
wait(dbTime)
db = false
end
end
local function closeMenu()
local plr = game.Players.LocalPlayer
if plr then
frame.Visible = false
plr.Character.Humanoid.WalkSpeed = 16
end
end
local function buyTool2()
local tool = game.ReplicatedStorage.ShopItems.Blaster
buyToolEvent:FireServer(tool)
end
local function buyTool3()
local tool = game.ReplicatedStorage.ShopItems.LaserGun
buyToolEvent:FireServer(tool)
end
open.Touched:Connect(shopMenu)
closeButton.MouseButton1Click:Connect(closeMenu)
buy2.MouseButton1Click:Connect(buyTool2)
buy3.MouseButton1Click:Connect(buyTool3)