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

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

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

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

2 comments

0

You cannot use an instance when using WaitForChild. Instead, you should use "game,Players.LocalPlayer.CharacterAdded:Wait()"

0

^ yea use that

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