So, my code is when I press "e" it destroys a model that is called Common Bacon and gives me ten coins. BUT, after that I can press e still and it'll STILL give me 10 coins, I want it to only give me ten coins if the Model "Common Bacon" is still there. Here's my code
local Plr = game.Players.LocalPlayer local model = workspace.CommonBacon local amountofcoins = 10 Plr:GetMouse().KeyDown:Connect(function(Key) if Key == "e" then wait (0.5) model:Destroy() Plr.leaderstats.Coins.Value = Plr.leaderstats.Coins.Value +10 end end)
In Roblox Studio, there's a method called FindFirstChild()
that can be used to see if something is in a given place, for example:
workspace:FindFirstChild("BasePlate")
This would return true as there is a child in the workspace called BasePlate.
For your script, all you'd have to do is to add an if statement that checks if the model is in the workspace:
local Plr = game.Players.LocalPlayer local model = workspace.CommonBacon local amountofcoins = 10 Plr:GetMouse().KeyDown:Connect(function(Key) if Key == "e" then wait (0.5) if workspace:FindFirstChild("CommonBacon") then model:Destroy() Plr.leaderstats.Coins.Value = Plr.leaderstats.Coins.Value +10 else print("Model has already been destroyed") end end end)