Accessing a Player's Character from the Workspace

I am able to access the player in the Players service but what can I do to access that player’s character in the workspace?

I’m trying to script a “detection” wherein if a player dies, the player’s scripts will be disabled.

This is what I’ve done so far:

local player = game.Players.LocalPlayer

if player.Humanoid.Health == 0 then

player.PlayerScripts:GetChildren().Disable = true

print('Script isnt running')

wait(2)

else

player.PlayerScripts:GetChildren().Disable = false

print('Script is running')

wait(2)

end

But as expected the output says:
Humanoid is not a valid member of Player "Players.brianruben2" - Client - LocalScript:3

Any feedback, tips, or advice will also be appreciated!

Might want to read documentation on the instance types you’re working with in the future. Players have a Character property that contains a reference to their character model.

2 Likes

Try thia out

local player = game.Players.LocalPlayer.Character

if player.Humanoid.Health == 0 then

player.PlayerScripts:GetChildren().Disable = true

print('Script isnt running')

wait(2)

else

player.PlayerScripts:GetChildren().Disable = false

print('Script is running')

wait(2)

end```
1 Like
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")
local Scripts = Plr:WaitForChild("PlayerScripts")

Hum.HealthChanged:Connect(function(Health)
	if Health <= 0 then
		for _, Script in ipairs(Scripts:GetChildren()) do
			if Script:IsA("Script") then
				Script.Disabled = true
			end
		end
		print("Player scripts have been disabled!")
	elseif Health > 0 then
		for _, Script in ipairs(Scripts:GetChildren()) do
			if Script:IsA("Script") then
				Script.Disabled = false
			end
		end
		print("Player scripts have been enabled!")
	end
end)

I’m going to assume this is what you were trying to achieve.