How to fire event from module script to server script?

now i have other problem. the random children that chosen can be the script and then it can remove it. that mean my script wont work if the random children will be chosen as the script

what i can do? can i filter that only ClassName “Parts” will be chosen? if yes how

Have it check if the instance IsA(“script”) or have it check the name. If name is script, then don’t delete, instead rerun the code.

Or just have the model being a child of the script.
Or check the position of the script in the table of the children. And then have it give you another random number if the # of the script is given.

how i can use isA(“script”) in my code?

I guess:
local RandomItemRemove=ChoosenMapCloneChildrens[math.random(1,#ChoosenMapCloneChildrens)]
while RandomItemRemove==nil or RandomItemRemove:IsA("Script")do
RandomItemRemove=ChoosenMapCloneChildrens[math.random(1,#ChoosenMapCloneChildrens)]
wait()
end

2 Likes

You could also use this but I won’t recommed looping through everything. I guess it’ll be more
“expensive” as it loops through all children. I’m not too sure but this would only be useful if you want to skip extra “wait()'s”:
local ChoosenMapCloneChildrens
for _,AmIAScriptOrNot_Hmmm in pairs(ChoosenMapClone:GetChildren())
if not AmIAScriptOrNot_Hmmm:IsA("Script")then
ChoosenMapCloneChildrens[#ChoosenMapCloneChildrens+1]=AmIAScriptOrNot_Hmmm
end
end

thank you very much working :smiley:

1 Like

working thank you very much :smiley:

1 Like

I’d also recommend making shorter variable names, these are a sort of pain to type out.

ok i will try thank you again :clap:

1 Like

Yeah, precisely what I meant ^
But for future use, I think just remember when your scripts can and can’t fire. And it always is worth a check with :IsA()!

1 Like