I need help getting the character from player, it keeps saying char is a nil value:
local plr = game.Players.LocalPlayer local char = plr.Character if not character or not character.Parent then character = plr.CharacterAdded:wait() end local chaos = realms:WaitForChild("Chaos") chaos.MouseButton1Down:connect(function() if plr.leaderstats.Level.Value >= 500 then char.Torso.CFrame = CFrame.new(777.8, 414.156, -667.8) end end)
You're checking for character
in your if statement, not char
. Also, that if statement is unnecessary, you can just use the or
operator after getting the character if it returns nil upon retrieving it the first time.
local player = game:GetService("Players").LocalPlayer -- Returns the character, or waits for it to load, then returns it. local char = player.Character or player.CharacterAdded:Wait() print(char) -- Prints the character every time