I find it pretty difficult and confusing to get the player, char, hum , or hum root part so could someone help me with that? I don't have a specific script to show but i'm confused.
✓ ANSWER ACCEPTED
How can i get the player, player character, humanoid and humanoid root part?
2 answers
✓ Accepted answer
If you are on a local script:
player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
humanoid = character:WaitForChild("Humanoid")
humanoidRootPart = character:WaitForChild("HumanoidRootPart")
If you're in a normal script, then it depends. Some ROBLOX events such as the event below give you the player, but you can't get the local player because there is no such thing in a normal script.
workspace.Part.Touched:Connect(function(hit)
if(hit.Parent:FindFirstChild("Humanoid"))then
local character = hit.Parent
humanoid = character.Humanoid
humanoidRootPart = character.HumanoidRootPart
end
end)
tell me what you want to do if on the server and i can help you
1 comment
0
thank you! both of your comments helped me out a lot!
Here's what you can use in the local script
local player = game.Players.LocalPlayer -- Player
repeat wait() until player.Character -- You can't use "WaitForChild" because character is not a member of player (player is in players tab while character is in the workspace) so you just gotta wait before the character of that local player appears
local character = player.Character -- Now you can define a variable of character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart") -- HumanoidRootPart is a member of character which means you can use "WaitForChild" (which will wait until the child in the brackets is loaded) to access it easier
local Humanoid = character:WaitForChild("Humanoid") -- same goes here, humanoid is a member of character so WaitForChild should do the job (just gotta change the word inside the brackets since we're waiting for humanoid
Tho you can't use it in workspace and some other tabs, but there you can use a normal script with this code inside:
game.Players.PlayerAdded:Connect(function(player)
-- Now we got the player. this is the same as local player
player.CharacterAdded:Connect(function(character)
--Waits until the character of the player is added, now you can define any child of character:
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
local Humanoid = character:WaitForChild("Humanoid")
end)
end)
Hope this helped.
1 comment
0
thank you! both of your comments helped me out a lot!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
i wish i could upvote