-
What do you want to achieve? A button that, once has been clicked, allows the player to delete certain models by clicking on the model.
-
What is the issue? For some reason I can’t figure out, when I click it for the first time it doesn’t do anything, then for the rest of the game when I click the button it instantly destroys without needing the second click. I would love some help
Local Script in Button
local pitch = {1,2,1.5,0.7}
local button = script.Parent
local player = game:GetService("Players").LocalPlayer
button.MouseButton1Up:Connect(function()
local mouse = player:GetMouse()
button.Press.PlaybackSpeed = pitch[math.random(1,#pitch)]
button.Press:Play()
button.MouseButton1Up:Once(function()
local target = mouse.Target
local name = target.Name
game:GetService("ReplicatedStorage").DestroyEvent:FireServer(target, name)
end)
end)
Script in ServerScriptService
local RemoteEvent = game:GetService('ReplicatedStorage').DestroyEvent
local function ServerEvent(player, target, name)
local funds = player:WaitForChild("leaderstats"):FindFirstChild("Funds")
local item = target.Parent
if item.Name == "Default" then
print("cannot destroy "..name)
game:GetService("Workspace").No:Play()
else
item:Destroy()
game:GetService("Workspace").Break:Play()
game:GetService("ReplicatedStorage").SellNotif:FireClient(player)
end
end
RemoteEvent.OnServerEvent:Connect(ServerEvent)