Hi everyone! I’m trying to weld a weapon to the player when they press a button. The weapon is welded to the player’s hand properly on the client but disappears after a few seconds which I found out is because the weld isn’t working on the server so it drops through the world and eventually gets destroyed. I tried to use a remote event to fire a script with a slightly modified version of the same code but that doesn’t seem to work.
Here’s the code (ignore the bits mentioning states, that’s something to do with how I’m handling player actions and 99.9% likely to not be part of the issue)
“Unsheathing” module script that acts on client side (working as intended):
local State = require(game:GetService("ReplicatedStorage").TGStateMachine).State
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Unsheath = ReplicatedStorage.TestSword:WaitForChild("Unsheath")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local state_unsheathing = State.new("Unsheathing")
state_unsheathing:RegisterFunction("EnterState", function(self)
local remoteEvent = ReplicatedStorage:WaitForChild("weaponWeldEvent")
local character = self.stateMachine.humanoid.Parent
local humanoid = self.stateMachine.humanoid
local remoteEvent = ReplicatedStorage:WaitForChild("weaponWeldEvent")
local Weapon = character:FindFirstChild("Weapon")
if Weapon then
print ("Weapon found")
local SideWeld = Weapon.PrimaryPart:FindFirstChild("SideWeld")
if SideWeld then
print ("SideWeld found")
SideWeld:Destroy()
Weapon:SetPrimaryPartCFrame(character:WaitForChild("Right Arm").CFrame*CFrame.new(0,-1,0)*CFrame.Angles(math.rad(-90),0,0))
local HandWeld = Instance.new("ManualWeld")
HandWeld.Part0 = Weapon.PrimaryPart
HandWeld.Part1 = character:WaitForChild("Right Arm")
HandWeld.C0 = HandWeld.Part0.CFrame:ToObjectSpace(HandWeld.Part1.CFrame)
HandWeld.Parent = HandWeld.Part0
remoteEvent:FireServer(character)
end
end
self.stateMachine:EnterState("CombatStanding")
end)
return state_unsheathing
Server Side WeaponWeldManager (isn’t working)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local weldRemoteEvent = ReplicatedStorage:WaitForChild("weaponWeldEvent")
local function weaponWeld(player, character)
print ("In weaponWeld")
print (character)
local character = character
local humanoid = character.Humanoid
local remoteEvent = ReplicatedStorage:WaitForChild("weaponWeldEvent")
local Weapon = character:FindFirstChild("Weapon")
if Weapon then
print ("Server Weapon found")
local SideWeld = Weapon.PrimaryPart:FindFirstChild("SideWeld")
if SideWeld then
print ("Server SideWeld found")
SideWeld:Destroy()
Weapon:SetPrimaryPartCFrame(character:WaitForChild("Right Arm").CFrame*CFrame.new(0,-1,0)*CFrame.Angles(math.rad(-90),0,0))
local HandWeld = Instance.new("ManualWeld")
HandWeld.Part0 = Weapon.PrimaryPart
HandWeld.Part1 = character:WaitForChild("Right Arm")
HandWeld.C0 = HandWeld.Part0.CFrame:ToObjectSpace(HandWeld.Part1.CFrame)
HandWeld.Parent = HandWeld.Part0
end
end
end
weldRemoteEvent.OnServerEvent:Connect(weaponWeld)
I know I need to replicate the weld on the server side but I searched for a solution and didn’t find anything that helped.
Here’s my explorer just in case something isn’t where it should be or I’m missing something essential
I’m making good progress on my game but this is a pretty big roadblock that’s preventing me from working on the core features and I want to make sure those are solid before adding anything extra to my game. Thank you to anyone who helps me solve this issue!