Hello.
I’m trying to make a weapon switching system. It works when I first spawn in, but after dying and respawning, it doesn’t seem to replicate to the server. Here’s the code for the client;
function changeWeapon(tool)
print("weapon changed")
if player.Character:WaitForChild("Humanoid").Health <= 0 then
warn("Player is dead. Weapon won't be changed")
return
end
-- move things around to make space for the new tool.
if tool then
local currentTool = character:FindFirstChildOfClass("Tool")
if currentTool then
character:FindFirstChild("WeaponInfo").Parent = currentTool
currentTool.Parent = player.Backpack
end
tool.Parent = character
weaponInfo = tool.WeaponInfo
tool.WeaponInfo.Parent = character
end
weaponId = weaponInfo.WeaponId.Value
if weaponModel then weaponModel:Destroy() end
if reloadTask then task.cancel(reloadTask) end
weaponModel = weaponIdInfo[weaponId].WeaponModel:Clone()
local reloadSound = playingSounds["Reload"]
if reloadSound then
reloadSound:Stop()
reloadSound:Destroy()
end
local tool = character:FindFirstChildOfClass("Tool")
if tool then
for _, part : BasePart in pairs(tool:GetDescendants()) do
if part:IsA("BasePart") then
part.LocalTransparencyModifier = 1
elseif part:IsA("ParticleEmitter") then
part.Transparency = NumberSequence.new(1)
end
end
end
weaponModel.Parent = workspace.ignore
animator = weaponModel.AnimationController.Animator
animations = quickFunctions.LoadAllAnimations(weaponModel.Animations.Viewmodel, animator)
weaponModelOffset = originalModelOffset * CFNew(0, -2, 0) * CFAngles(math.pi/2, math.pi/4, 0)
end
I can try to send specific parts of either server or client code. There’s a lot of code and it’s really hard to track the source of the issue, so you might need to describe what part specifically. I checked if the server was equipping the weapon at all, and it isn’t. I don’t know much about replicating tools, so any help would be very much appreciated.