Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script works fine in studio but doesn't work at all in game, help?

I've made a script that changes your t-shirt when you click a textbutton, it works fine in studio but doesn't work at all, saying that everything is a nill value. I've tried the script in both a localscript and a standard one with no prevail. Can someone help me?

This is the script:

local decal = script.Parent:findFirstChild("Decal")
local hit = game.Players.LocalPlayer
local humanoid = hit.Character:findFirstChild("Humanoid")
local torso = hit.Character:findFirstChild("Torso")
	
function GetFace()
	if torso ~= nil and humanoid ~= nil then
		local shirt = hit.Parent:findFirstChild("Shirt Graphic")
		if shirt ~= nil then
			shirt.Graphic = decal.Texture
		else
			local altshirt = torso:findFirstChild("roblox")
			if altshirt ~= nil then
				altshirt.Texture = decal.Texture
			else
				print("Torso found. Shirt not found. Assumed to be a robot.")
			end
		end
	else
		print("Not a valid person! T-Shirt cannot be changed!")
	end
end

script.Parent.MouseButton1Click:connect(GetFace)

6 comments

0

Does it print anything?

0

Nope, just an error saying hit a nil value.

0

Can you give the exact errors?

0

You're trying to index LocalPlayer from the workspace.

0

Is this a SurfaceGui?

0

game.Players.LocalPlayer Is this in a local script or a normal script?

1 answer

Your issue is that you are attempting to call LocalPlayer in a ServerScript.

Simply converting your script to a localscript should do the trick.

This discussion is preserved as it was. New answers, comments, and votes are closed.