I’m currently working on a game mode in my game in which a player can get a special weapon (The holy stick). This bit of code makes the player drop their holy stick when they die, but the issue is, if the HolyStickHolder value changes more than once, they drop more than they should ( > 1). Here’s my code:
function DropWeapon(Player,Weapon)
local DroppedWeapon = game.ReplicatedStorage.Objects.Weapons:FindFirstChild(Weapon):Clone()
DroppedWeapon:PivotTo(Player.Character.HumanoidRootPart.CFrame * CFrame.new(0,5,0))
DroppedWeapon.Parent = game.Workspace.Temp
DroppedWeapon.Stick.Velocity = 0
game.ReplicatedStorage.GlobalVariables.HolyStickHolder.Value = nil
for _,Child in pairs(DroppedWeapon:GetDescendants()) do
if Child:IsA("Part") or Child:IsA("MeshPart") or Child:IsA("UnionOperation") then
Child:SetNetworkOwner(nil)
end
end
end
game.ReplicatedStorage.GlobalVariables.HolyStickHolder:GetPropertyChangedSignal("Value"):Connect(function()
local Value = game.ReplicatedStorage.GlobalVariables.HolyStickHolder.Value
if Value ~= nil then
local Notif = game.ReplicatedStorage.RemoteEvents.AquireHolyStick:FireAllClients(Value)
local Character = Value.Character
local Connection
Connection = Character:WaitForChild("Humanoid").Died:Connect(function()
if Character:FindFirstChildWhichIsA("Tool") then
Character:FindFirstChildWhichIsA("Tool"):Destroy()
end
DropWeapon(Value,"HolyStick")
Connection:Disconnect()
end)
end
end)
Does anyone know what’s going on here?