#Kick players when a humanoid in Workspace dies

1 messages · Page 1 of 1 (latest)

waxen basalt
#

I would like to make a script that kicks all players when the parent of the script (a humanoid) dies. How could I do this?

quasi coralBOT
#

studio** You are now Level 4! **studio

waxen basalt
#

not really ^^"

candid pasture
#

use humanoid.Died:Connect(function()

end)

jagged canyon
#

I'll write on phone so there will be errors

candid pasture
#

i think im missing a parameter in the function but i dk

jagged canyon
# waxen basalt not really ^^"

Game.Players.PlayerAdded:Connect(function(plr)

Local char = plr.Character or plr.CharacterAdded:Wait()

local hum = char:FindFirstChildOfClass("Humanoid")
Hi.Died:Connect(function()
Plr:Kick()
End)
End)

#

Am on phone

#

So autocorrect and shit

#

Just use auto complete in studio

#

To fix my typos

tawny wave
#

if i understand correctly when even one person dies everyone is kicked?

#

i dont see why but heres how

#

on a player joining you could input their humanoid into a table and remove it if they leave (memory leak avoidance) and then loop through that table every time its changed and set up a conncetion to the humanoid died even and if one of them fires it kicks all players

jagged canyon
#

Oh all players

#

Shit mb

jagged canyon
tawny wave
#

true

jagged canyon
#

But table would be needed if u want not instantly so like when they enter a round or smth

waxen basalt
#

The server size is only 1 player btw, I should've mentioned that, and the thing that is dying is a separate humanoid that is not a player's humanoid

astral hinge
waxen basalt
astral hinge
#

what other humanoids do you want dead when the player dies

quasi coralBOT
#

studio** You are now Level 4! **studio

astral hinge
#

like, npcs orrrr

#

whats the context

candid pasture
#

if i'm understanding correctly, they want to kick the player when a humanoid (not the player's humanoid) dies

quasi coralBOT
#

studio** You are now Level 2! **studio

astral hinge
#

whats the context to that

#

i think itd help if we knew what they're trying to do

candid pasture
#

yeah wheres the humanoid located

#

we cant exactly use an event corresponding to a humanoid if we dont know where the humanoid is

waxen basalt
#

oh, I just want the humanoid of an NPC to run a script that kicks the player when it dies. It's just inside a model in the workspace

candid pasture
#

yeah but what's the model called

#

we cant do anything if we dont know where it is

#

@waxen basalt

#

sorry for ping btew

astral hinge
#

this is relatively easy

#

and we could spoonfeed you but

#

i think its better you learn yourself

#

how? you may ask

#

well, first find out how to get the humanoid in a script

#

then find out how to detect if it died, theres an event for it

candid pasture
#

read the studio docs too

astral hinge
#

then figure out how to kick the player

#

you add all of that together and your script is complete

#

tell us when you get stuck somewhere

astral hinge
#

not rn at least

candid pasture
#

it will for the event

#

you could also do humanoid. and check out the properties n events n stuff it shows as a list, but you need to know how to use it to run the kick code

waxen basalt
#

I'm at school atm, so I'm not always able to reply right away ^^"

#

sorry, that's wrong. The model is in the workspace and is named "Dummy", the humanoid is named "Enemy"

candid pasture
#

ok so you have to find out how to get Enemy From Dummy, Dummy being from Workspace in a script

#

then from there you have to use an event for when Enemy dies and run a function from the event

#

after that put your kick code in the function

waxen basalt
#

I'm finding another way to do it, by having a separate variable change when the enemy is damaged, but it changes by 50 then...doesn't change again.
here is my code:

local humanoid = dummyModel:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        -- Deal 10 damage to the Dummy's Humanoid
        humanoid:TakeDamage(50)
        local enemyHealth = (enemyHealth - 50)
        print(enemyHealth)
        if enemyHealth <= 0.1 then
            print("enemy dead")
        end
#

it should work, right..? it sets enemyHealth to itself minus 50, or it should...

#

but whenever- oh wait, ohhh

#

ah, the script has enemyHealth = 100, so it just...changes it back to 100 ^^"

#

hm...

#

how do I access a variable in a module?

#

the Roblox Scripting website thing doesn't make any senseee

jagged canyon
#

U want have variable in module that other scripts can access?

waxen basalt
#

I want to create a variable that ANY script can access, if that's possible

waxen basalt
#

well, that...really limits things.

jagged canyon
#

If module is required by local script and by server script

#

It's 2 diffrent copies

#

Basically

waxen basalt
#

only scripts tho, not local scripts..? is that possible..?

jagged canyon
#

U would have to use remote to sync them it

jagged canyon
#

That's how modules work

waxen basalt
#

how do I use one..?

jagged canyon
#

Multiple scripts can access it

waxen basalt
#

I think I'v egotten it set up, I just don't know how to access the variable in a script...

jagged canyon
#

U just do
module.VariableName = value

#

No local word

waxen basalt
#

I see... where do I put the module..?

candid pasture
#

serevrscriptservice iirc

waxen basalt
#

kk, thx

jagged canyon
#

Well if it's server then obv not on client side

waxen basalt
#

eh, that doesn't matter tbh

#

what else do I need to do to have a script be able to access the module?

candid pasture
#

also, is your script requiring the module?

waxen basalt
#

how do I do that again..?

jagged canyon
#

Local module = require(pathtomodule)

candid pasture
#

pathtomodule being game.ServerScriptService.module

jagged canyon
#

If that's your hierarchy then ye

candid pasture
#

module being, well, whatever your module's name is

#

obviously assuming your module is in serverscriptservice

waxen basalt
#

for the module, is this correct?

local module = {}
entityHealth.EnemyHealth = 100
entityHealth.PlayerHealth = 100
return module

#

module is named entityHealth

jagged canyon
#

No

#

In module u gonna use whatever your table is named

#

Like

#

It's named module

waxen basalt
#

it's named entityHealth for me

jagged canyon
#

So u gonna do module.EnemyHealth

jagged canyon
jagged canyon
#

That's your module

#

U gonna use that name .EnemyHealth

#

So if you got
local whatever = {}

return whatever

#

U can do whatever.EnemyHealth = 100

waxen basalt
jagged canyon
#

Look at first and last name of your code

candid pasture
#

btw quick unrelated tip if you ever want to modify an integer from a script you can use +=, -= and iirc *=

jagged canyon
#

Not the one u written

waxen basalt
#

local module?

jagged canyon
#

Default one

jagged canyon
#

That's what u gonna hse

#

Use

#

To create other variables

waxen basalt
#

but I would like to name it something I remember...how can I change it..?

jagged canyon
#

Accessable by other scripts

jagged canyon
#

Just make sure to change in last line too

waxen basalt
#

but you said I have to have the module part thing named...not what I have it...

#

not entityModule..?

#

sorry, I'm slow ^^"

jagged canyon
#

But again the name of that won't impact how u use it in other scripts

jagged canyon
#

So

#

every module is made like

#

local module = {}
return module

#

Right?

#

So If. You want to create variables accessable by other scripts

#

U do module.Variable = 100

#

Inside the module

#

You can change the module to anything, just change it in first and last line

#

Whatever u call it won't impact how u use the module in diffrent scripts

waxen basalt
#

ah, I fixed it, thank you!

quasi coralBOT
#

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

waxen basalt
#

I understand!~

#

sorry for taking so long to understand ^^"

jagged canyon
#

Dw

waxen basalt
#

okay! so I now have a section in my code that can detect when the humanoid is dead... what's the command to kick the player..?

jagged canyon
candid pasture
#

btw not really important but those are called methods

#

functions are sets of methods that can be called after they're created

#

they can also have their own variables

waxen basalt
#

I see..!

#

ugh, one more thing: in roblox studio, the game is perfectly bright, but in the ACTUAL game, it's pitch-black

candid pasture
#

you probably have a script altering the brightness somewhere

waxen basalt
#

I see..

candid pasture
#

probably like serverscriptservice or starterplayerscripts

#

did you perhaps import any free models (hopefully not)?

waxen basalt
#

I think I did for a fullbright script, but...I thought I got rid of them all, I don't see anything...

waxen basalt
#

I do also know that importing free models is generally risky... idk why I did it for fullbright, but...ehh