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

Why is player.Character NOT working?

In my game I'm developing, it teleports you to a farm thats NOT already taken (To prevent players from wandering around, trying to find an empty plot). I've used this small teleporting lines many times before - which is listed below (I was using a local script while using THIS code, so that could be a reason why it won't work.)

--LocalScript
local player = game.Players.LocalPlayer
local torso =  player.Character.LowerTorso
torso.CFrame = -- Insert object path here

My script is here - inside ServerScriptService

--Script
game.Players.PlayerAdded:Connect(function(player)
	local tele1 = game.Workspace.Plot.tele
	local tele2 = game.Workspace.Plot2.tele
	local tele3 = game.Workspace.Plot3.tele
	local LowerTorso = player.Character.LowerTorso
	if game.ReplicatedStorage.Farms["1"].Value == true then
		if game.ReplicatedStorage.Farms["2"].Value == true then
		 	LowerTorso.CFrame = tele3.CFrame
		end
		if game.ReplicatedStorage.Farms["2"].Value == false then
		 	LowerTorso.CFrame = tele2.CFrame
		end
	else
		LowerTorso.CFrame = tele1.CFrame
	end
end)

I modified it a little, just so it would work in a normal script. But it still won't work. Te only thing the console says is 'Line 5'. If you could help, that would be a great! Thank you in advance.

2 answers

Try doing this.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local lowtor = Character:WaitForChild("LowerTorso")

Because here it's going to wait for the event to fire and if it fires and the player is found then you have the character.

I think this would work, if not let me know so I can revise it.

3 comments

0

Now it's returning an error on this line - local Character = Player.Character or Player.CharacterAdded:Wait()

0

Also, I don't think that 'game.Players.LocalPlayer' works inside a Normal Script. Am I right?

0

"game.Players.LocalPlayer" works in LocalScripts only

Hmm.. Make sure that your game only allows R15 if you're going to use LowerTorso. Generally, I would recommend using HumanoidRootPart as all players have that, making it easier to work with.

Have you tried de-bugging with print? Sometimes the output will error a line if it uses a line that's nil or has something wrong with it. Weird that it's not telling you why it errored.

With what killer said, there's some stuff wrong with that. If those lines are in a Local Script, then you shouldn't be waiting for the character to load with the local script. Instead, try doing that with the server script.

This might help

local player = game:GetService("Players").LocalPlayer
local torso =  player.Character:WaitForChild("HumanoidRootPart")
torso.CFrame = CFrame.new(X,Y,Z)

If that doesn't work, let me know!

4 comments

0

Oh, sorry. I meant it IS a normal Script.

0

And i figured out that 'player.Character' is the thing that is messing it up

0

Hello?

0

Hi! Sorry for the late response. That's because you cant use game.Players.LocalPlayer with a normal script! If you want to do this, use a local script and couple it with a remote event!

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