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

How to find hummanoid in StarterGui?

I am trying to make a gui that kill the player and i cant find a way how to call a player

script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local human = player:FindFirstChild("Humanoid")
if (human ~= nil) then 
		human.Health = 0 
	end
	Blur.Size = 3
end)

2 answers

✓ Accepted answer

Alright so you have a problem with the script you provided and I will go over it with you so heres your script

script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local human = player:FindFirstChild("Humanoid")
if (human ~= nil) then 
        human.Health = 0 
    end
    Blur.Size = 3
end)

alright so first off Humanoid is located inside of Character so that would mean if you wanted to get Humanoid you would need to define Character so look

local player = game.Players.LocalPlayer --Gets player Locally 
local char = player.Character --Gets Character from player
--Alright so basically you would need to define humanoid through character here
local humanoid = char:WaitForChild("Humanoid") -- So we have found humanoid which means main part of script is done index is done

script.Parent.MouseButton1Click:Connect(function()--function for clicked
if (humanoid~=nil)then
	humanoid.Health = 0--If humanoid nil then it dies
end--ends if statement 
Blur.Size = 3--blurs screen by 3
end)--Ends function

so now we have finished the new script I hope you learned something new and if this helped then accept if you want

Hello! This should do the job: (this is a localscript inside the button)

local player = game:GetService("Players").LocalPlayer -- game:GetService('Players') returns Player objects(check this guide:http://developer.roblox.com/en-us/api-reference/function/Players/GetPlayers),  while .LocalPlayer gets the local player(the player to whom the starter gui is shown)

script.Parent.MouseButton1Down:connect(function() --function that fires when the player clicks on the button gui

    if player.Character and player.Character:FindFirstChild("Humanoid") then--checking if they exist

        player.Character.Humanoid.Health = 0 --sets the player's health to 0 causing him to die

    end

end)

Hopefully this is easy to understand its a pretty simple code :)

2 comments

0

you also missed the part where the dude wanted to blur his screen

0

thats what that was thanks for telling me im new i didnt think of that

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