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

What can I add to clickbutton script to can killing by click?

Hello! I'm making clickbutton script which can switch team and kill by click, but I don't know what can I add to kill this person whick clicks that. Any ideas?

local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	Player.Team = game:GetService("Teams").Guest;
end)

1 answer

✓ Accepted answer

Hello! There are a few ways you could go about this actually.

The first method is using Humanoid:LoadCharacter()

local Player = game:GetService("Players").LocalPlayer
local humanoid = Player.Character:FindFirstChild("Humanoid")

humanoid:LoadCharacter() --This simply respawns the character

The second method you can use is changing the humanoids health to 0

local Player = game:GetService("Players").LocalPlayer
local humanoid = Player.Character:FindFirstChild("Humanoid")

humanoid.Health = "0" --This will kill the player!

The last method that I know of is using the humanoid TakeDamage function

local Player = game:GetService("Players").LocalPlayer
local humanoid = Player.Character:FindFirstChild("Humanoid")

humanoid:TakeDamage(100) --This will damage the player, taking away ultimately health, pretty much method 2. 

I hope this was able to help you! Any questions? Comment down below, and I'll be glad to help!

Don't forget to mark as the solution if this helps you!

5 comments

0

attempt to index upvalue 'humanoid' (a nil value)

0

Channge :FindFirstChild to :WaitForChild("Humanoid")

0

And make sure you spell Humanoid with a capital "H", LUA is case sensitive!

0

nice, now it works, thank you!

0

No problem! Happy scrpting!

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