Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Zeluxis 100
6 years ago

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)
0
Does it print anything? RockerCaleb1234 282 — 6y
0
Nope, just an error saying hit a nil value. Zeluxis 100 — 6y
0
Can you give the exact errors? Nowaha 459 — 6y
0
You're trying to index LocalPlayer from the workspace. PyccknnXakep 1225 — 6y
View all comments (2 more)
0
Is this a SurfaceGui? PyccknnXakep 1225 — 6y
0
game.Players.LocalPlayer Is this in a local script or a normal script? GoldenPhysics 474 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

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

Ad

Answer this question