#Killing a player with a script

117 messages · Page 1 of 1 (latest)

hybrid saddle
#

i have been trying to make a script that once you step on a part it puts you in a team and respawns you but for some reason player:LoadCharachter() and Humanoid.Health = 0 doesn't work even if it's a server script and not a local script

mellow isle
#

So you want to kill the player, right?

hybrid saddle
#

well

#

not exactly kill him

#

i jsut want him to respawn

mellow isle
#

You could teleport him to where it will respawn or kill him and it will respawn

cunning anvilBOT
#

studio** You are now Level 32! **studio

mellow isle
#

!rank

cunning anvilBOT
hybrid saddle
#

and i cant kill a player when hes in a lobby

#

i said i need a way to respwan him

#

not to teleport

wide marten
#

is this server script

hybrid saddle
#

yes

wide marten
#

try take damage method

hybrid saddle
#

and what is that

wide marten
#

humanoid:TakeDamage(9999)

hybrid saddle
#

ohhh

#

ok

#

ill try

#

allso how do i reference the chrachter in a server script

#

cus there is no LocalPlayer in a server script

mellow isle
wide marten
#

bruh i cant read

mellow isle
mellow isle
#

As long as you have the player you can easily get the character by just looking for the model

wide marten
#

he says respawn

wide marten
#

Player.Character

mellow isle
#

Yea, in a script

hybrid saddle
#

in a local script its Player.LocalPlayer.Charachter

mellow isle
wide marten
#

in server script its Player.Character

hybrid saddle
#

k thanks

mellow isle
#

mind blowing

hybrid saddle
#

idk if theres a bug or im just stupid

mellow isle
#

Humanoid.Health = 0

hybrid saddle
#

bro i tried that

mellow isle
#

Any error in output?

hybrid saddle
#

let me check

mellow isle
#

Hold up

wide marten
#

spelling error

hybrid saddle
wide marten
# hybrid saddle
local function respawn(part)
  part.Parent:FindFirstChild("Humanoid):TakeDamage(999)
end

touchpart.Touched:Connect(respawn)
mellow isle
#

You forgot to close ""

hybrid saddle
#

i fixed that

cunning anvilBOT
#

studio** You are now Level 5! **studio

mellow isle
#

But you should check if part is a child of a model

hybrid saddle
#

dw

hybrid saddle
#

thank you so much

wide marten
#

np

mellow isle
#
local function respawn(part)
  local char = part.Parent
  if not char then return end

  local hum = char:FindFirstChild("Humanoid")
  if not hum then return end

  hum:TakeDamage(999)
end

touchpart.Touched:Connect(respawn)
hybrid saddle
mellow isle
#

This way you will not encounter any issue

hybrid saddle
#

thanks for helping

mellow isle
hybrid saddle
#

alright

mellow isle
#
function onRespawn()
  --code
end

function onTouch(part)
  local char = part.Parent
  if not char then return end

  local hum = char:FindFirstChild("Humanoid")
  if not hum then return end

  hum:TakeDamage(999)
  onRespawn()
end

touchpart.Touched:Connect(onTouch)
#

You could do something like this

hybrid saddle
#

oh that works too

#

didnt think abt that

#

thanks

#

Thank you so much @wide marten and @mellow isle

#

wait

#

wth

mellow isle
#

You're welcome

hybrid saddle
#

didnt work

mellow isle
#

What happened?

#

Show the code

hybrid saddle
wide marten
hybrid saddle
#

and how do i fix it

#

and how does it even take an argument

#

if its on another line

wide marten
#

onTouched(otherPart) the otherpart is the argument

mellow isle
#

You should add in () the part variable

hybrid saddle
#

ohhh

#

ok

#

wait what

#

im so confused

mellow isle
#
function onRespawn(otherpart)
  print(otherPart)
end

function onTouch(part)
  local char = part.Parent
  if not char then return end

  local hum = char:FindFirstChild("Humanoid")
  if not hum then return end

  hum:TakeDamage(999)
  onRespawn(part)
end

touchpart.Touched:Connect(onTouch)
hybrid saddle
#

everything works

#

thank you so much man

mellow isle
#

Here is an example:

function func2(i)
  print("Function 2: "..i)
end

function func1(n)
  print("Function 1: "..n)
  func2(n)
end
func1("Hi There")
latent waspBOT
#
Program Output
Function 1: Hi There
Function 2: Hi There

hybrid saddle
mellow isle
#

At which line?

hybrid saddle
#

and if you keep it empty

hybrid saddle
#

im just wondering

#

like its not in my code im just wondering why is there a big difference between keeping it empty or typing something there

wide marten
mellow isle
#

;compile

function func2(i)
  i += 1
  print("Function 2: "..i)
end

function func1(n)
  n += 1
  print("Function 1: "..n)
  func2(n)
end
func1(1)

-------------

function func2_new()
  print("Function 2: empty")
end

function func1_new(n)
  n += 1
  print("Function 1: "..n)
  func2_new()
end
func1_new(1)
latent waspBOT
#
Program Output
/opt/wandbox/lua-5.4.3/bin/lua: prog.lua:2: syntax error near '+'

mellow isle
#

shit, I fucked up with the syntax, I write it in Discord lol

#

ah yes, same name functions, Im smart

hybrid saddle
#

k

mellow isle
#

Ok Im sad now, wait a sec

hybrid saddle
#

im just wondering cus im new to scripting

#

i hope you get happier lol

mellow isle
#

nvm, its working...

#

Looks like the compile bot is just dumb

hybrid saddle
#

k it makes sence now

#

thanks

mellow isle
#

Hope so, Im not that good at teaching and/or explaining

hybrid saddle
#

and im not good at learning