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)
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)
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)
: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)