I am working on a game on roblox and i notice that some people spam the button to spawn tons of cars and then it starts to make the game laggy because they cars are spawning inside each other. Can someone help me make it where they cant spam the text button. This is the script to make the car spawn and check the price. Btw im a noob on coding lua scripts. This is what my stuff looks like. My Gui, script, and where the button is.

script.Parent.MouseButton1Click:Connect(function()

if script.Parent.Parent.Purchased.Value == true then

-- Spawn it

game.ReplicatedStorage.SpawnCar:FireServer(script.Parent.Parent.Name)

else

--Let them purchase it

local PriceOfItem = game.ReplicatedStorage:WaitForChild("CheckPrice"):InvokeServer(script.Parent.Parent.Name)

if game.Players.LocalPlayer.leaderstats.Cash.Value >= PriceOfItem and script.Parent.Parent.Purchased.Value == false then

-- The player has enough cash

game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - PriceOfItem

script.Parent.Parent.Purchased.Value = true

script.Parent.Text = "Spawn"

end

end

end)

2 comments

0

i dont feel like making a script so ill explain it instead after they bought the car, if they press the button it checks if it can find the car in workspace and if it does then return end else spawn the car

0

cant see the picture