I have this script that should weld a part to the player when the remote event is fired. This works in studio, however when I test it in a server, I get this error. Is it because I'm trying to access the players GUI from the server?

00:17:29.082 - CharacterCustomizationUI is not a valid member of PlayerGui


-- Server Script -- 
function weld(p1,p2,c0)
	local w = Instance.new("Weld",p1)
	w.Part0 = p1
	w.Part1 = p2
	w.C0 = c0 or p1.CFrame:inverse() * p2.CFrame
	return w
end

function PerformWeld(player)
local DataLoad = player.Character:WaitForChild("PlayerData")	
local PlayerAttire = DataLoad:FindFirstChild("AttireData")
local WD = DataLoad.WeldingAids:FindFirstChild("WeldData")
local Weldee = DataLoad.WeldingAids.Weldee
local PE = player.Character:FindFirstChild("PlayerEquipment")

local Outfit = game.ServerStorage.GlobalStorage.Attire:FindFirstChild(Weldee.Value):Clone()
	local char = player.Character or player.CharacterAdded:wait()
	local Garment = Outfit:WaitForChild(WD.Value.."Components")
	local CurrentSection = Garment:Clone()
	CurrentSection.Parent = char
	local H = Instance.new("StringValue")
	H.Name = ("Hair")
	H.Parent = CurrentSection

	for _,v in pairs(CurrentSection:GetChildren()) do
		if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
			v.Anchored = true
			
		end
	end
	
	CurrentSection.Parent = PE

	for _,v in pairs(CurrentSection:GetChildren()) do
		if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
			if v ~= CurrentSection["ArmorCore"] then
				weld(v, CurrentSection["ArmorCore"])
			end
		end
	end
	
	local CurrentSectionWeld = weld(CurrentSection["ArmorCore"], char[WD.Value], CFrame.new())
	
	for _,v in pairs(CurrentSection:GetChildren()) do
		if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
			v.Anchored = false
			v.CanCollide = false
			
			--print ("Welded "..WD.Value)
		end
	end
end


function DescendList(player)
	local DataLoad = player.Character:WaitForChild("PlayerData")
	local WD = DataLoad.WeldingAids:FindFirstChild("WeldData")	
	local Weldee = DataLoad.WeldingAids.Weldee
	local Hat = player.Character.PlayerEquipment.FakeHeadComponents
	Hat:Destroy()
	local Helm = DataLoad.AttireData.OutfitHelmet
	local T = player.PlayerGui:WaitForChild("CharacterCustomizationUI")
	Helm.Value = T.CurrentFrame.SelectedTrim.Value
	Weldee.Value = Helm.Value
	WD.Value = ("FakeHead")
	PerformWeld(player)
	
	print("Trimmed")
end

local event = game.ReplicatedStorage:WaitForChild("HaircutEvent") -- make sure the event in in ReplicatedStorage
event.OnServerEvent:connect(function(player) -- OnServerEvent automatically passes the player who fired it as the first argument.	
DescendList(player)
    
end)
--Local Script--
local player = game:GetService("Players").LocalPlayer 

script.Parent.MouseButton1Click:connect(function()
	script.Parent.Parent.SelectedTrim.Value = script.Parent.Haircut.Value
	player.Character.PlayerData.AttireData.OutfitHelmet.Value = (script.Parent.Haircut.Value)
    local e = game.ReplicatedStorage:WaitForChild("HaircutEvent")
    e:FireServer()

end)


Thanks for any help!

2 comments

1

If CharacterCustomizationUI was made using a LocalScript then yes, this would be the reason.

1

I don't think you can access .PlayerGui with filtering enabled