Gear won't work

Hello. I was making a gear where you can drop explosives.
The problem is: the UI does not go away after being unequipped, and the gear won’t drop the item from the ReplicatedStorage.

SCRIPTS:
Localscript:

local button = script.Parent.toolbutton
local pressed = false

script.Parent.Equipped:Connect(function()
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	if player.PlayerGui:findFirstChild("toolbutton") == nil then
		local gui = button:Clone()
		gui.Parent = player.PlayerGui
	end
end)

script.Parent.Unequipped:Connect(function()
	wait()
	if gui then gui:Destroy() end
end)

button.TextButton.MouseButton1Click:Connect(function()
	pressed = true
	if pressed == true then
		script.RemoteEvent:FireServer()
		wait(0.01)
		pressed = false
	end
end)

Handler: (server)

wait(0.2)

local event = script.Parent

event.OnServerEvent:Connect(function()
	local item = game.ReplicatedStorage.dropped_explosive
	local clone = item:Clone()
	clone.Parent = game.Workspace
	clone:MoveTo(script.Parent.Parent.Parent.dropplaceholder)
end)
3 Likes

The scope of the gui variable is not global. Here is a fixed version for destroying your UI:

local button = script.Parent.toolbutton
local pressed = false
local gui

script.Parent.Equipped:Connect(function()
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	if player.PlayerGui:findFirstChild("toolbutton") == nil then
		gui = button:Clone()
		gui.Parent = player.PlayerGui
	end
end)

script.Parent.Unequipped:Connect(function()
	wait()
	if gui then gui:Destroy() end
end)

button.TextButton.MouseButton1Click:Connect(function()
	pressed = true
	if pressed == true then
		script.RemoteEvent:FireServer()
		wait(0.01)
		pressed = false
	end
end)
1 Like

As for explosive not being dropper, MoveTo() accepts Vector3, meaning position. You have to give position of your dropplaceholder:
clone:MoveTo(script.Parent.Parent.Parent.dropplaceholder.Position)

The handler solution does not work.

:MoveTo() works with models too and it accepts a vector3
unlike pivotto it moves the model to fully empty area so it doesnt get stuck (so on or above the vector3)

1 Like

Here are the properties in the explorer for anyone that wants it.
image
image