I am trying to make a gui that kill the player and i cant find a way how to call a player
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | local player = game.Players.LocalPlayer |
3 | local human = player:FindFirstChild( "Humanoid" ) |
4 | if (human ~ = nil ) then |
5 | human.Health = 0 |
6 | end |
7 | Blur.Size = 3 |
8 | end ) |
Alright so you have a problem with the script you provided and I will go over it with you so heres your script
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | local player = game.Players.LocalPlayer |
3 | local human = player:FindFirstChild( "Humanoid" ) |
4 | if (human ~ = nil ) then |
5 | human.Health = 0 |
6 | end |
7 | Blur.Size = 3 |
8 | 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
01 | local player = game.Players.LocalPlayer --Gets player Locally |
02 | local char = player.Character --Gets Character from player |
03 | --Alright so basically you would need to define humanoid through character here |
04 | local humanoid = char:WaitForChild( "Humanoid" ) -- So we have found humanoid which means main part of script is done index is done |
05 |
06 | script.Parent.MouseButton 1 Click:Connect( function () --function for clicked |
07 | if (humanoid~ = nil ) then |
08 | humanoid.Health = 0 --If humanoid nil then it dies |
09 | end --ends if statement |
10 | Blur.Size = 3 --blurs screen by 3 |
11 | 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)
01 | 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) |
02 |
03 | script.Parent.MouseButton 1 Down: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 |
11 | end ) |
Hopefully this is easy to understand its a pretty simple code :)