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

How to find hummanoid in StarterGui?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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 :)

0
you also missed the part where the dude wanted to blur his screen DuckyRobIox 280 — 4y
0
thats what that was thanks for telling me im new i didnt think of that Mast3rStRix 43 — 4y

Answer this question