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

Getting the player in the workspace?

local Lplayerid = script.Parent.Parent.User.Value
local lhum = tostring(Lplayerid)

local hum = game.Workspace.lhum.HumanoidRootPart

This is in a regular script that's why I took the player from a stringvalue. Any help would be appreciated!

EDIT : Btw everything everything in the script works expect the local-player workspace part.

5 comments

0

Could you please explain what this is for? Why does this need to be in a Server Script?

0

It's in a regular script not in the server.

0

Yes, regular script, server script, same thing. I believe Server Script would be the proper term for it tho, anyway. I need some context, what is this for?

0

Look at the title...

0

Players.6zk8.PlayerGui.ScreenGui.TextLabel.Script:3: attempt to index nil with 'HumanoidRootPart' <<< That's the error

2 answers

✓ Accepted answer

If all you're trying to do is get the HumanoidRootPart from the player's Character then you can use a local script for this then use a RemoteEvent to fire the server from the localscript and use a server script to do the rest of the code if you want anything to be server sided. Example:

Local Script:


local player = game.Players.LocalPlayer
local character = player.Character
local Hum = character.HumanoidRootPart
local RemoteEvent = game.ReplicatedStorage.RemoteEvent

-- Any code you want for the local script, if all the code you want to be Server-Sided then skip this

RemoteEvent:FireServer()

Server Script:


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local character = player.Character
	local Hum = character.HumanoidRootPart

	-- Code

end)

5 comments

0

Can you do player.Character in a server script?

0

Yes, but to be able to get the player you need an event. Like I did in the server script, you're getting the player that fired the RemoteEvent.

0

No you don't, I have a stringvalue with a localscript makin the value the localplayer.

0

Yeah, I don't think that will work.

0

Fixed.

local LocalPlayer = game.Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character
local Hum = LocalPlayerCharacter.HumanoidRootPart

3 comments

0

Doesn't work.

0

You cannot use LocalPlayer inside a regular script.

0

Look what I did up there.

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