Trying to get player name for workspace

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to get the player’s humanoid in workspace

  2. What is the issue? I
    Can’t figure out anything

  3. What solutions have you tried so far?
    I looked everywhere

local ScreenGui = script.Parent
local BlurEffect = game.Lighting.Blur
local ScrollingFrame = ScreenGui.ScrollingFrame
local Play = ScreenGui.Play


Play.MouseButton1Click:Connect(function()
	BlurEffect.Enabled = false
	ScreenGui.Enabled = false
	
	if game.Workspace.**PlayerName.Humanoid.Health == 0** then
		BlurEffect.Enabled = true
		ScreenGui.Enabled = true
	end 
end)

Look at the line with the stars.

local player = game.Players.LocalPlayer
local Character = player.Character

Or if it’s a Gui that is already existent before the character spawns:

Player.CharacterAdded:Connect(function()
end)

or

Character.Added:Wait()
local Player = game:GetService("Players").LocalPlayer
local ScreenGui = script.Parent
local BlurEffect = game.Lighting.Blur
local ScrollingFrame = ScreenGui.ScrollingFrame
local Play = ScreenGui.Play


Play.MouseButton1Click:Connect(function()
	BlurEffect.Enabled = false
	ScreenGui.Enabled = false
	
	if game.Workspace[Player.Name].Humanoid.Health == 0 then
		BlurEffect.Enabled = true
		ScreenGui.Enabled = true
	end 
end)
1 Like

Thank you for fixing it. 3_0 chars

1 Like

nevermind it did not work ooff

Is it a local script? 3_0 chars

What type of script is this? A localscript? If so, where is it located?

yes it is a local script 3_0 chars

it is inside the screenGui 3_0 chars

local ScreenGui = script.Parent
local BlurEffect = game.Lighting.Blur
local ScrollingFrame = ScreenGui.ScrollingFrame
local Play = ScreenGui.Play
local PlayerName = game.Players.LocalPlayer.Name

Play.MouseButton1Click:Connect(function()
	BlurEffect.Enabled = false
	ScreenGui.Enabled = false

	
	if game.Workspace.PlayerName.Humanoid.Health == 0 then
		BlurEffect.Enabled = true
		ScreenGui.Enabled = true
	end 
end)

read it again

I’m not sure why you modified the script but if you use my method it would’ve work…

I think what you can do is add

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")

Then in your if statement, just change it to

if Hum.Health == 0 then

I was trying to get the player 's name so I can find the player in workspace

Yes and mine does exactly just that lol

I will try it thank you
3_0 chars

local ScreenGui = script.Parent
local BlurEffect = game.Lighting.Blur
local ScrollingFrame = ScreenGui.ScrollingFrame
local Play = ScreenGui.Play
local Player = game.Players.LocalPlayer
local Character = workspace.WaitForChild(Player.Name,120)

Play.MouseButton1Click:Connect(function()
	BlurEffect.Enabled = false
	ScreenGui.Enabled = false

	
	if Character.Humanoid.Health == 0 then
		BlurEffect.Enabled = true
		ScreenGui.Enabled = true
	end 
end)

You don’t need to get the model like that, LocalPlayer has a property called Character, which is the Model of the player in workspace. And if it’s not loaded by then, CharacterAdded will wait for the Character to be added

2 Likes

It works thank you alot 3_0 chars

1 Like

Right, I’m not that great when it comes to getting the Character from the Player. Thanks for reminding me that exists.

1 Like

Glad to be of help to you! If you have anymore issues don’t e afraid to make another post!

1 Like