I tried turning off the resetonspawn property but that didn’t work. I tried a bunch of other things and those options didn’t work either and that’s why i’m here.
The Code is probably not the problem as I troubleshooted it.
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local backpack = player:WaitForChild("Backpack")
local dropevent = game.ReplicatedStorage.Drop
local hadToolEquipped = false
humanoid.Died:Connect(function()
for i, tool in pairs(character:GetChildren()) do
if tool:IsA("Tool")then
dropevent:FireServer(hadToolEquipped, tool, character)
end
end
end)
Server Script:
local dropevent = game.ReplicatedStorage.Drop
dropevent.OnServerEvent:Connect(function(player, hadToolEquipped, tool, character)
hadToolEquipped = true
tool.Parent = game.Workspace.DroppedWeapons
local equippedTool = player.Backpack:FindFirstChildOfClass("Tool")
if equippedTool then
equippedTool.model.CFrame = character.HumanoidRootPart.CFrame
equippedTool.model.Anchored = false
wait(1)
equippedTool.model.Anchored = true
end
end)
You’re trying to change a variable (which was defined on the client), but you can’t do that because it is not the same script. Instead, you could put that inside the humanoid died function.
Also, you did not need to include the player character in the event argument. You can just reference it in the server script using player.Character.
I have modified your two scripts, since the hadToolEquipped argument is irrelevant in the dropevent.
Server Script
local dropevent = game.ReplicatedStorage:WaitForChild("Drop")
dropevent.OnServerEvent:Connect(function(player, tool)
local character = player.Character
tool.Parent = game.Workspace.DroppedWeapons
local equippedTool = player.Backpack:FindFirstChildOfClass("Tool")
if equippedTool then
equippedTool.model.CFrame = character.HumanoidRootPart.CFrame
equippedTool.model.Anchored = false
wait(1)
equippedTool.model.Anchored = true
end
end)
LocalScript
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local backpack = player:WaitForChild("Backpack")
local dropevent = game.ReplicatedStorage.Drop
local hadToolEquipped = false
humanoid.Died:Connect(function()
for i, tool in pairs(character:GetChildren()) do
if tool:IsA("Tool")then
hadToolEquipped = false
dropevent:FireServer(tool)
end
end
end)