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

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

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

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

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

01local player = game.Players.LocalPlayer --Gets player Locally
02local char = player.Character --Gets Character from player
03--Alright so basically you would need to define humanoid through character here
04local humanoid = char:WaitForChild("Humanoid") -- So we have found humanoid which means main part of script is done index is done
05 
06script.Parent.MouseButton1Click:Connect(function()--function for clicked
07if (humanoid~=nil)then
08    humanoid.Health = 0--If humanoid nil then it dies
09end--ends if statement
10Blur.Size = 3--blurs screen by 3
11end)--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)

01local 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)
02 
03script.Parent.MouseButton1Down:connect(function() --function that fires when the player clicks on the button gui
04 
05    if player.Character and player.Character:FindFirstChild("Humanoid") then--checking if they exist
06 
07        player.Character.Humanoid.Health = 0 --sets the player's health to 0 causing him to die
08 
09    end
10 
11end)

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