#enemies touches base once and script works but the second enemy script no workk
1 messages · Page 1 of 1 (latest)
** You are now Level 2! **
enemies will be cloned from serverstorage to game.workspace.mobingame(folder) if you need this info
and maybe id be very thankful if you know how to fix the first npc moved into the abse and the game stops for like 0.25s
no i would be very thankful
Hello
Ik why
First of all, when u assign the variable hmob u are waiting to assign only 1 instance (so one clone)
(And not all the clones)
So same thing for variable mob, btw idk why u used hmob, since u didnt used it in ur script
You want that when u clone a mob from the server storage, its goes to the mobingame folder, and THEN, you will check all the mobs in that folder
To check all the mobs in that folder, the easiest way would be first to convert it to a table, an array of all mobs inside the folders
To do that u can do : lua workspace.mobingame:GetChildren() you can now here have the table of all the mobs inside ur folder
GetChildren gives u all the children of the folder or a instance, and makes it as a table (an array precisely)
So when something is touching, you need to check and get the table of all rigs, and in this table, go and see for key, value in this table if the value is equal to the ennemy, if ye then u code ur things
U want me do the code or u wanna do it urself?
Idk if i explained well or even if its an optimal way but thats working if im not wrong
Btw if u need more explanation dont hesitate
wait so to sum up what i do wrong is i only check a single mob not all of the folder itself?
i tried getchildren but it just end up destroying all the enemies if only one touches the base
how do i call the children individualy inside the getchildren's table?
also what do you mean when you mentioned "key" here
i redo the scripts but this time the enemies just dont destroy
i think something is wrong with line "if enemy == mob" or "local mob" but i dont know what is wrong
oh yeah i think i fixed it but enemies just spam the you lose promt instead of doing it once for eaach enemy but ill make it in a different channel
Yes
Thats the main and only reason i can see
I meant a for loop inside the table, u look every onstance in the table and check which one is the same as the instance that touched the base (ennemy)
Yes obviously
When u do get childrens at the start
It do it immediatly
so what should i do
Because when u cloned the rigs ot smthing like that, the script didnt find it cuz it did this action before the cloning
What should you do is
Whne the base is touched
You will crrate a variable
That will get all the children of the folder
Then
You will do a for loop
Inside the table
To check if the ennemy is equal to one of the instances in the folder
So one of the mobs
So u need to local mobs when the base its touched
U understood or no?
If u still dont i can make the script for u
i think you should make a script for me cause i lowkey dont understand it
but i kinda fixed the problem being mobs cant destroy but i kept warning me it cant find do something but the script works
ill reocrd rq
U sure u dont even want to try? Im just telling u to :
when the base is touched u will set a variable called mobs, and u will set it to the folder:GetChildren() and then you will do a for loop in table (idk fi u know whats a for loop in table so?) inside this loop you will look if the ennemy = a mob in the table
wait me a bit ill show u the fixed version
Its just cuz u can get better if u do it urself, and try, if u cant ill give u the script
while waiting for u to respond i asked chat gpt and used it in my script
Ah
Ok u want me to do the script?
and mobs spamming you lose once it touches the base
Copy paste me ur script if yes
im trying to log into studio it kept kicking me out
Why?
i got in
yeah lowkey
just to see what my script is missing
heres the version i asked chat gpt
the error and touch spamming
Copy paste me the script pls @granite warren
** You are now Level 7! **
oh yeah mb
local base = script.Parent
local basehp = 3
local hmob = game.Workspace.mobingame:WaitForChild("Rig"):WaitForChild("Humanoid") -- enemies will be cloned to mobingame folder
local mob = game.Workspace.mobingame:GetChildren()
local mobfolder = game.Workspace.mobingame
base.Touched:Connect(function(enemytouchedbase)
local enemy = enemytouchedbase.Parent and enemytouchedbase
if enemy:IsDescendantOf(mobfolder) then-- if enemy = the children inside the mobingame folder then do this
enemy:Destroy()
print("enemy has touched base")
basehp = basehp - 1
print("the base health is now:", basehp)
if basehp <= 0 then
print("you lose")
end
end
end)
Im on mobile so it will be a bit hard but i should be able i wait
im going to sleep rn so you can have as much time writing your script as you want
ill respond to ur messages when u wake up
bye g
local base = script.Parent
local basehp = 3
base.Touched:Connect(function(partThatIsTouching)
local enemy = partThatIsTouching.Parent
local mobs = game.Workspace.mobingame:GetChildren()
for _, mob in ipairs(mobs) do
if enemy == mob then
mob:Destroy()
print("enemy has touched base")
basehp = basehp - 1
print("the base health is now:", basehp)
end
end
if basehp <= 0 then
print("you lose")
end
end)
should be working
Ill check it when im at home thabks for the sceipt