I have a tool and I’m trying to detect when the player drops it, however every way I try to detect it none of them get called.
local UIS = game:GetService("UserInputService")
local tool = script.Parent
local config = require(tool:WaitForChild("Config"))
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local ui = nil
local equipped = false
local debounce = false
local reloading = false
local ammo = 0
local spareAmmo = 0
ammo = config.maxAmmo
spareAmmo = config.defaultSpareAmmo
local holdAnim = config.holdAnim
local holdTrack = nil
if holdAnim ~= nil then
holdTrack = char:WaitForChild("Humanoid"):LoadAnimation(holdAnim)
end
UIS.InputBegan:Connect(function(input, processed)
if processed == true then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch or input.KeyCode == Enum.KeyCode.ButtonR2 then
Fire()
end
if input.KeyCode == Enum.KeyCode.R then
if ammo < config.maxAmmo then
Reload()
end
end
end)
function Fire()
if equipped and not debounce and not reloading and ammo > 0 then
debounce = true
ammo -= 1
local character = player.Character or player.CharacterAdded:Wait()
tool:WaitForChild("Fire"):FireServer(mouse.Hit.p, character)
ui:WaitForChild("Ammo").Text = ammo.."/"..spareAmmo
task.wait(config.fireRate)
debounce = false
elseif ammo <= 0 then
Reload()
end
end
function Reload()
if ammo < config.maxAmmo and equipped and not reloading and spareAmmo > 0 then
reloading = true
local toAdd = config.maxAmmo - ammo
if spareAmmo >= toAdd then
spareAmmo -= toAdd
config.ReloadSound:Play()
task.wait(config.reloadTime)
ammo = config.maxAmmo
ui:WaitForChild("Ammo").Text = ammo.."/"..spareAmmo
reloading = false
else
spareAmmo = 0
task.wait(config.reloadTime)
ammo += spareAmmo
ui:WaitForChild("Ammo").Text = ammo.."/"..spareAmmo
reloading = false
end
end
end
tool.Equipped:Connect(function()
equipped = true
player = game.Players.LocalPlayer
char = player.Character
mouse = player:GetMouse()
ui = tool:WaitForChild("GunUI") or player.PlayerGui:WaitForChild("GunUI")
ui.Parent = player.PlayerGui
ui:WaitForChild("GunName").Text = tool.Name
ui:WaitForChild("Ammo").Text = ammo.."/"..spareAmmo
if holdTrack ~= nil then
holdTrack:Play()
end
end)
tool.Unequipped:Connect(function()
equipped = false
ui.Parent = tool
if holdTrack ~= nil then
holdTrack:Stop()
end
end)
workspace.ChildAdded:Connect(function(child)
if child == tool then
equipped = false
ui.Parent = tool
if holdTrack ~= nil then
holdTrack:Stop()
end
end
end)
I’ve tried ChildAdded, ChildRemoving, DescendantAdded, tool:GetPropertyChangedSignal(“Parent”), on both the workspace and tool
Nothing gets called, I’ve looked at other posts similar and none worked.