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

I want to move a model to character's position, it works in studio but in game I get error?

Asked by 6 years ago

So it works in studio but not in game and I get this error:

11:15:20.766 - Players.Player1.PlayerGui.Main.SpawnTycoon.LocalScript:10: attempt to index global 'chr' (a nil value)

Here's the script:

t = game.Lighting.Tycoon:Clone()
plr = game.Players.LocalPlayer
chr = plr.Character
bd1 = plr.Stats.BuxDrop
td1 = plr.Stats.TixDrop
bagdrop1 = plr.Stats.BagDrop
script.Parent.MouseButton1Click:Connect(function()
    t.Parent = game.Workspace
    t.Name = plr.Name
    t:MoveTo (Vector3.new(chr.LeftLowerArm))

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

add game.Workspace:WaitForChild(game.Players.LocalPlayer) to the beginning of the script

it works in studio because it runs faster, and in the game it will not register the var immediately after the game has started

0
You cannot use an instance when using WaitForChild. Instead, you should use "game,Players.LocalPlayer.CharacterAdded:Wait()" hiimgoodpack 2009 — 6y
0
^ yea use that AttentionHog 70 — 6y
Ad

Answer this question