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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Rinextel 291 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
attempt to index upvalue 'humanoid' (a nil value) ThadonROOX 47 — 4y
0
Channge :FindFirstChild to :WaitForChild("Humanoid") Rinextel 291 — 4y
0
And make sure you spell Humanoid with a capital "H", LUA is case sensitive! Rinextel 291 — 4y
0
nice, now it works, thank you! ThadonROOX 47 — 4y
0
No problem! Happy scrpting! Rinextel 291 — 4y
Ad

Answer this question