Once I tried that I got an error saying the baseShield couldn’t be cloned on line 15
What line 15 is
shield = baseShield:clone()
In the serverscript? And the local script still points to script.Parent.Parent?
Yes the error occurs in the ServerScript and script.Parent.Parent is defined in the LocalScript and ServerScript.
The serverscript shouldn’t need the baseShield defined as a separate variable. Just ensure that it is within the parameters of both of the remote events.
Should I remove it from the Server Script?
As a variable, yes.
When I do that the “baseShield” get’s a blue line under it and I get an error saying it’s a nil value.
Can I see the serverscript?
Server Script
game.ReplicatedStorage.Events:WaitForChild("Equip_Event").OnServerEvent:Connect(function(player, ...)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local equipped = false
local up = false
local shield
local UserInputService = game:GetService('UserInputService')
local lsh = character.Torso:findFirstChild("Left Shoulder")
equipped = not equipped
lsh.Part1 = character["Left Arm"]
print("Step1")
if equipped then
shield = baseShield:clone()
local handle = shield:findFirstChild("Handle")
for n,i in pairs(shield:GetChildren()) do
if i.Name ~= "Handle" and i:IsA("BasePart") then
local nw = Instance.new("Weld",i)
nw.Part0 = handle
nw.Part1 = handle
nw.C0 = handle.CFrame:inverse()
nw.C1 = i.CFrame:inverse()
elseif (i:IsA("Script") or i:IsA("LocalScript")) then
i:remove()
end
end
handle.Anchored = false
print("Step2")
shield.Parent = character
shield:MakeJoints()
local nw = Instance.new("Weld",character["Left Arm"])
nw.Part0 = character["Left Arm"]
nw.Part1 = handle
nw.C1 = CFrame.new()
nw.Name = "LeftGrip"
else
if character["Left Arm"]:FindFirstChild("LeftGrip") then
character["Left Arm"].LeftGrip:remove()
end
if shield then
shield:remove()
end
print("Step3")
end
end)
game.ReplicatedStorage.Events:WaitForChild("Raise_Event").OnServerEvent:Connect(function(player, ...)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local equipped = false
local up = false
local baseShield = player.Backpack.Shield1
local shield
local lsh = character.Torso:findFirstChild("Left Shoulder")
local UserInputService = game:GetService('UserInputService')
up = not up
if up then
lsh.Part1 = nil
local w = Instance.new("Weld",shield)
w.Part0 = character.Torso
w.Part1 = character["Left Arm"]
w.C1 = CFrame.new(1.2,-.25,0.05) * CFrame.fromEulerAnglesXYZ(math.rad(-75),math.rad(55),0)
else
for n,i in pairs(shield:GetChildren()) do
if i.ClassName == "Weld" then
if i.Part0 == character.Torso then
i.Parent = nil
end
end
end
lsh.Part1 = character["Left Arm"]
end
end)
should be
game.ReplicatedStorage.Events:WaitForChild(“Equip_Event”).OnServerEvent:Connect(function(player, baseShield)
And same for the other event.
And then remove local baseShield = bla bla from both events.
Also, you don’t need to put
Local player = game.Players.Localplayer
Because it is already passed in the parameters and serverscripts can’t access the localplayer anyways.
Thank you.
The shield welds to my arm when I press V but when I press X to raise it, it doesn’t raise.
Also when I press V again the shield is supposed to disappear but stays on my arm. Do you know how to fix that?
For both problems, you’ll have to make sure that the function has access to the shield that the player is currently holding. To do this, when destroying the shield or raising it,instead of refering to the shield variable,you’ll have to find the shield model that is parented to the character.
i.e player.Character.Base_Shield:Destroy()
I discovered what was going on. The second RemoteEvent was not firing because I set equipped to false because I forgot I moved all the code to the Server. Once I fixed that I was able to fire the event however it didn’t raise my shield because my shield is actually a nil.
Do you know what I would define my shield as?
Again,you’ll have to define the shield variable as the shield the character is holding (the shield model should be a parent of the character)
local shield = character.Shield_Name