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

Getting the player in the workspace?

Asked by
6zk8 95
4 years ago
Edited 4 years ago
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.

0
Could you please explain what this is for? Why does this need to be in a Server Script? xInfinityBear 1777 — 4y
0
It's in a regular script not in the server. 6zk8 95 — 4y
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? xInfinityBear 1777 — 4y
0
Look at the title... 6zk8 95 — 4y
0
Players.6zk8.PlayerGui.ScreenGui.TextLabel.Script:3: attempt to index nil with 'HumanoidRootPart' <<< That's the error 6zk8 95 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
Can you do player.Character in a server script? 6zk8 95 — 4y
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. xInfinityBear 1777 — 4y
0
No you don't, I have a stringvalue with a localscript makin the value the localplayer. 6zk8 95 — 4y
0
Yeah, I don't think that will work. xInfinityBear 1777 — 4y
0
Fixed. 6zk8 95 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
local LocalPlayer = game.Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character
local Hum = LocalPlayerCharacter.HumanoidRootPart
0
Doesn't work. 6zk8 95 — 4y
0
You cannot use LocalPlayer inside a regular script. xInfinityBear 1777 — 4y
0
Look what I did up there. 6zk8 95 — 4y

Answer this question