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