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

Why doesn't this script work in-game[Solved]?

Asked by 9 years ago

The script seems to be fine and works in Play-Solo but when I tested it in-game it doesn't seem work so I clicked f9 and check the error message which says "Players.UserOnly16Characters.PlayerGui.ScreenGui.Frame.ImageButton.Cloth:6: attempt to index upvalue 'Me' (a nil Value). I don't know why the error only came up in-game and not in Studio?!? D:

local Player = game.Players.LocalPlayer
local Me = Player.Character

script.Parent.MouseButton1Click:connect(function()

local Humanoid = Me:FindFirstChild("Humanoid")
 if Humanoid then

for i,v in pairs (Me:GetChildren()) do
 if v:IsA("Pants") or v:IsA("Shirt") or v:IsA("CharacterMesh") or v:IsA("Hat") then
    v:remove()
end

if v:IsA("Part") then
    v.BrickColor = BrickColor.new("Mid gray")
end end 

print("Recoloured Part and Removed Junk")

for i,v in pairs (Me.Head:GetChildren()) do
if v:IsA("Decal") then
   v:remove()
end end

print("Remove Face Decal")

local A = Instance.new("Shirt", Me)
A.Name = "Shirt" 
A.ShirtTemplate = "http://www.roblox.com/asset/?id=227899193"

print("Added Shirt")

local B = Instance.new("Pants",Me)
B.Name = "Pants"
B.PantsTemplate = "http://www.roblox.com/asset/?id=188558593"

print("Added Pants")

local C = Instance.new("Decal",Me.Head)
C.Name = "face"
C.Texture = "http://www.roblox.com/asset/?id=133620200"

print("face Added")

local Hat = Instance.new("Hat", Me)
local Handle = Instance.new("Part", Hat)
      Handle.Name = "Handle" 
Handle.Size = Vector3.new(1,1,1)
local Mesh = Instance.new("FileMesh", Hat.Handle)
Mesh.MeshId = "http://www.roblox.com/asset/?id=13070796"
Mesh.TextureId = "http://www.roblox.com/asset/?id=13070807"

local hat = game.ReplicatedStorage.LongHairHeadBand:Clone()
hat.Parent = Me

local Hair = game.ReplicatedStorage["Ultra-Fabulous Hair"]:Clone()
Hair.Parent = Me
end 
end)

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

The error is one line 2.

local Me = Player.Character

Me is nil here because the Player's Character hasn't yet loaded. To fix this, we have to check if Me is nil, and wait for the CharacterAdded event to fire if it is:

local Me = Player.Character
if not Me then
    Me = Player.CharacterAdded:wait()
end

Which can be written on one line like so:

local Me = Player.Character or Player.CharacterAdded:wait()
0
The script is a Local Script which is a Part of a Gui that is inside the StarterGui. I know you say the script work fine but it doesn't seem to work fine in-game. UserOnly20Characters 890 — 9y
0
PS you can edit comments by clicking on them. adark 5487 — 9y
0
Thanks and Thank you for the tip :) UserOnly20Characters 890 — 9y
Ad

Answer this question