#Kick players when a humanoid in Workspace dies
1 messages · Page 1 of 1 (latest)
** You are now Level 4! **
Do u know basics
not really ^^"
use humanoid.Died:Connect(function()
end)
i think im missing a parameter in the function but i dk
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
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
I mean u could just on player added listen do humanoid.died
And when died just loop thro game.Players:Getplayers() and kick
true
But table would be needed if u want not instantly so like when they enter a round or smth
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
do you still need help with this
yes, I do, thank you
what other humanoids do you want dead when the player dies
** You are now Level 4! **
if i'm understanding correctly, they want to kick the player when a humanoid (not the player's humanoid) dies
** You are now Level 2! **
ohhh
whats the context to that
i think itd help if we knew what they're trying to do
yeah wheres the humanoid located
we cant exactly use an event corresponding to a humanoid if we dont know where the humanoid is
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
yeah but what's the model called
we cant do anything if we dont know where it is
@waxen basalt
sorry for ping btew
well
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
read the studio docs too
then figure out how to loop through all the players in the server or just get that one specific and kick them
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
it will for the event
the event for when a humanoid dies can be found here https://create.roblox.com/docs/reference/engine/classes/Humanoid
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
oh, so sorry. The model is just labeled "dummy" I believe, with the Humanoid "Humanoid"
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"
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
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
Explain more
U want have variable in module that other scripts can access?
I want to create a variable that ANY script can access, if that's possible
Well any not rly
Cuz
well, that...really limits things.
If module is required by local script and by server script
It's 2 diffrent copies
Basically
only scripts tho, not local scripts..? is that possible..?
U would have to use remote to sync them it
Ye
That's how modules work
how do I use one..?
Multiple scripts can access it
I think I'v egotten it set up, I just don't know how to access the variable in a script...
I see... where do I put the module..?
serevrscriptservice iirc
kk, thx
Anywhere, but in workspace exploiters could still see the code
Well if it's server then obv not on client side
eh, that doesn't matter tbh
what else do I need to do to have a script be able to access the module?
also, is your script requiring the module?
require
how do I do that again..?
Local module = require(pathtomodule)
pathtomodule being game.ServerScriptService.module
If that's your hierarchy then ye
module being, well, whatever your module's name is
obviously assuming your module is in serverscriptservice
for the module, is this correct?
local module = {}
entityHealth.EnemyHealth = 100
entityHealth.PlayerHealth = 100
return module
module is named entityHealth
it's named entityHealth for me
So u gonna do module.EnemyHealth
No no
Look first and last line
That's your module
U gonna use that name .EnemyHealth
So if you got
local whatever = {}
return whatever
U can do whatever.EnemyHealth = 100
why would I name it that? entityHealth is simpler, no?
Am not sure u understand
Look at first and last name of your code
btw quick unrelated tip if you ever want to modify an integer from a script you can use +=, -= and iirc *=
Not the one u written
local module?
Default one
Yes
That's what u gonna hse
Use
To create other variables
but I would like to name it something I remember...how can I change it..?
Accessable by other scripts
U can just change module to anything
Just make sure to change in last line too
but you said I have to have the module part thing named...not what I have it...
not entityModule..?
sorry, I'm slow ^^"
But again the name of that won't impact how u use it in other scripts
Hear me out
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
ah, I fixed it, thank you!
** You are now Level 5! **
Dw
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..?
to kick a player u do player:Kick()
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
I see..!
ugh, one more thing: in roblox studio, the game is perfectly bright, but in the ACTUAL game, it's pitch-black
you probably have a script altering the brightness somewhere
I see..
probably like serverscriptservice or starterplayerscripts
did you perhaps import any free models (hopefully not)?
I think I did for a fullbright script, but...I thought I got rid of them all, I don't see anything...
yep, I've expanded everything and don't see anything I don't recognize. I did delete the stuff under lighting, but...idk, I don't see anything I could add for actual physical lighting...
I do also know that importing free models is generally risky... idk why I did it for fullbright, but...ehh