Why is my button not working?

  1. 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.

  2. 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)

use MouseButton1Clicked instead.

That did not work.

post character minimum

Try adding breakpoints to the code and see if its the button’s problem or the code’s problem

Can you elaborate on this? These 2 contradict each other, do you need 2 clicks to destroy it or just 1? (sorry if I misunderstood you)

Once you click the button it hides it (not yet implemented) then you click on where you want to destroy it

This thread will probably never be looked at again but anyway, the issue was that the second function was a button click and not just a mouse click.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.