Hello there, I have been trying to fix something. I know that it’s not the correct code for this line but I cannot find the code it should be. Any help?
local plr = game.Players.LocalPlayer (This should not be this, this is the line)
local mouse = plr:GetMouse()
function onClick()
if plr.Character:FindFirstChild(“RightArm1”) == nil then
local g = script.Parent.Parent.Backpack:Clone()
g.Parent = plr.Character
local C = g:GetChildren()
for i=1, #C do
if C[i].className == “Part” or C[i].className == “UnionOperation” or C[i].className == “WedgePart” or C[i].className == “MeshPart” then
local W = Instance.new(“Weld”)
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new(“Weld”)
Y.Part0 = plr.Character.Torso
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "WedgePart" or C[i].className == "MeshPart" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
You cannot use LocalPlayer in server scripts, please use a Local Script, and the first argument in the connection from the click is the player. This should be the script:
function onClick(plr)
if plr.Character:FindFirstChild(“RightArm1”) == nil then
local g = script.Parent.Parent.Backpack:Clone()
g.Parent = plr.Character
local C = g:GetChildren()
for i=1, #C do
if C[i]:IsA( “BasePart”) then
local W = Instance.new(“Weld”)
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new(“Weld”)
Y.Part0 = plr.Character.Torso
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "WedgePart" or C[i].className == "MeshPart" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
function onClick(plr)
if plr.Character:FindFirstChild(“RightArm1”) == nil then
local g = script.Parent.Parent.Backpack:Clone()
g.Parent = plr.Character
local C = g:GetChildren()
for i=1, #C do
if C[i]:IsA( “BasePart”) then
local W = Instance.new(“Weld”)
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new(“Weld”)
Y.Part0 = plr.Character.Torso
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == “Part” or C[i].className == “UnionOperation” or C[i].className == “WedgePart” or C[i].className == “MeshPart” then
h[i].Anchored = false
h[i].CanCollide = false
end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)
function onClick(plr)
if plr.Character:FindFirstChild("RightArm1") == nil then
local g = script.Parent.Parent.Backpack:Clone()
g.Parent = plr.Character
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "WedgePart" or C[i].className == "MeshPart" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = plr.Character.Torso
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or C[i].className == "UnionOperation" or C[i].className == "WedgePart" or C[i].className == "MeshPart" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
end