Script doesnt work in game but does in studio

hello, i made a script a while ago that turns the player body parts into a forcefield and then back to normal, work just fine in studio but makes me invisible in the actual game, why???

here’s the code, It was working before but now its broken :confused:

local Players = game:GetService("Players")

local function onCharacterAdded(character) 

	local SavedColorTable = {}
	local enabled = false

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("BasePart") then

			SavedColorTable[Child.Name] = Child.Color
			print(SavedColorTable)

		end
	end

	task.wait(0.5)

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("BasePart") then

			Child.Color = Color3.fromRGB(255, 255, 255)


			Child.Material = 'ForceField'

		end
	end

	task.wait(0)

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("Accessory") then

			local ChildA = Child:FindFirstChildWhichIsA("Part")


			ChildA.Color = Color3.fromRGB(255, 255, 255)


			ChildA.Material = 'ForceField'

		end
	end

	task.wait(3) -- time until it returns to normal

	for bodypart, color in pairs (SavedColorTable) do
		character[bodypart].Color = color
	end

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("BasePart") then

			Child.Material = 'Plastic'

		end
	end

	task.wait(0)

	for i,Child in pairs (character:GetChildren()) do
		if Child:IsA("Accessory") then

			local ChildA = Child:FindFirstChildWhichIsA("Part")


			ChildA.Color = Color3.fromRGB(255, 255, 255)


			ChildA.Material = 'Plastic'

		end
	end

end

local function onPlayerAdded(player)
	player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Not exactly sure if this is related entirely to your problem but when I tried to run the script this happened
“ServerScriptService.Script:37: attempt to index nil with ‘Color’ - Server - Script:37”, and it just turned my body parts into a forcefield but not the hat I usually wear and since it errored it never turned them back. but when I removed the hat I was wearing it worked fine like it is meant to.

Go into your actual game and get into the developer console (either through the settings menu or typing /console) and screenshot what you see when you go into the server output

for your error, check if your game is in R6 and put the server script in ServerScriptService, the actual issue is this:

1 Like

I’ve tried to find a solution but it’s kinda a roblox client error. I also tested with high-graphics and low-graphics. It’s the same. Also tried to set to Enum.Material.ForceField or adding pcall!

roblox client
image
roblox studio
image

1 Like

No point in going around it, we gotta sit down and wait for them to fix it, unless they don’t known that this is a current issue