#ModuleScript executed 14 being called only once.

1 messages · Page 1 of 1 (latest)

odd dagger
#

Setting up a PVP system, and made a Module for a VFX that is going to be called a lot of times in different skills. I call it only once on KokusenHitbox, but for some reason it is called 12 - 14x (and after some seconds it is executed once more). I'm attaching the two codes at this post.

urban abyss
odd dagger
#

here

#

and the event is fired on a localscript in StarterCharacterScripts

#

i'm sending it

#

wait

#

kokusen hitbox is executed a lot of times too

#

and kokusenhitboxevent is the same

urban abyss
# odd dagger

So Touched fires for each piece of the player, so that will fire many times. hit will never be a model, as Models cannot touch, it'll only be parts within the model

pallid micaBOT
#

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

odd dagger
#

so if it touches the torso and the head

#

it will fire 2 times

urban abyss
odd dagger
#

yeah but how can i fix it?

#

i think i cant just put "hit" and not "hit: Model"

urban abyss
# odd dagger yeah but how can i fix it?

Keep track of what players you've touched to make sure you're not touching the same player twice.

You'd probably have to check to see when the player has stopped touching too, so they can activate the event again, so probably TouchEnded until none of that player's parts are touching anymore

urban abyss
urban abyss
odd dagger
urban abyss
# odd dagger so i make the same player cant "touch" twice until the touched event ends

Well there's a more simple solution of just adding a cooldown, called a debounce, where you set some variable to false when the event occurs (you'd have to make that per-player though) and if it's false for that player, don't run the code, something like this: https://devforum.roblox.com/t/hitboxtouched-keeps-repeating/2021358/7

More complex would be to keep track of what parts of that player are touching, and only reset the value when every one of that player's parts stop touching

odd dagger
urban abyss
odd dagger
#

dont care about the wrong "then return endA" i made it while printing the screen

urban abyss
#

You have to move the debounce variable outside of the connect function

urban abyss
#

otherwise it'll always start as false, thus always allowing it

odd dagger
#

now the part isn't created at the time of the touch, but 1 second later something like that

#

the player thing i'm doing later

urban abyss
# odd dagger

you should only set the debounce to true after a successful creation, so inside the if

odd dagger
#

did it

#

but the delay still appears

#

oh

#

its because of hit service

#

basically in hitservice there's a wait to until the knockback is false

#

and the explosion was being affected by it

#

so when i moved the explosion to before it the module worked

#

now i'm making the player thing

odd dagger
#

@urban abyss well it stills hits only 1 player

#

also, for some reason i cant change its rate

#

i made a parameter for it

#

look

#

function module:CreateExplosion(plr, anchored, rate)
VFX.Rate = rate

#

and in kokusenhitbox i put it as 1

#

just for testing

pale vector
#

make it hit only the humanoidrootpart

#

i read some of your code and i think it only hits one person cuz you made a debounce check up there

odd dagger
pale vector
#

you can create a hitboxmodule that makes all the checks and separates the players that you hit in models and not parts

odd dagger
#

if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") and hit ~= nil and hit.Name = "HumanoidRootPart" then

pallid micaBOT
#

studio** You are now Level 3! **studio

odd dagger
#

so i would do something like this?

#

oh

pale vector
odd dagger
#

and the ==

pale vector
#

you can make hit.Parent ~= plr.Character

odd dagger
#

yeah

pale vector
#

also if you have another parts inside the player parts like accesories if could bug your code

odd dagger
#

nothing was changed at all but when doing this i dont need to do the debounce thing anymore?

#

so i can delete it

pale vector
#

most attacks hits multiple ppl

odd dagger
#

its because the vfx

#

was being created multiple times

#

because it was hitting right arm, left arm and multiple things so the event was being fired multiple times

#

and then vfx sttacked

#

and it was weird

pale vector
#

ah that makes sense

odd dagger
#

well for some reason only 1 npc was ragdolled and knockbacked

#

also

#

i'm being ragdolled

pale vector
odd dagger
#

oh wait

#

name

#

sorry

#

.Name

#

well dont ask me why but it stills hits only 1 character

#

and i made the hitbox larger so it is probably not bc it only touches one hrp

pale vector
#

try to debug it printing the parts that were hit

odd dagger
#

ok

#

only 1 time clicking g (the trigger key)

#

and it touched both characters

#

dummy 1 and dummy 2

#

3 humanoidrootparts for some reason, the third one isnt my character cuz when i click g with no target it only prints that the event was fired

pale vector
#

try to use workspace:GetBoundsInBox() instead of hitbox.Touched

pale vector
odd dagger
#

thats why debounces are useful tho

odd dagger
pale vector
#

its quite easy

#

it makes a imaginary box in the workspace with the size and cframe you give it

#

and returns all the parts inside or touching that imaginary box

#

also its a workspace method

odd dagger
#

so i set the CFRAME as the same as the hitbox one right

pale vector
#

and you can give it a OverlapParams object

pale vector
#

and dont forget the size

odd dagger
#

i'm making a variable for it

pale vector
#
local overlapparams = OverlapParams.new()
            
overlapparams.FilterType = Enum.RaycastFilterType.Exclude
overlapparams.FilterDescendantsInstances = {character}
#

then you can make something like this

#

and it will ignore your character

odd dagger
#

well whats RaycastFilterType?

#

just to knnow

#

know

#

@pale vector also

#

i think it isnt possible

#

to have

#

any other player

#

with the same username

#

only the displayname

#

also for some reason i cant change the particleemitter's rate

pale vector
pale vector
pale vector
#

it basically tells the method you it should treat the FilterDescendantsInstances

odd dagger
pale vector
#

the KokusenVFX its a particle emitter?

odd dagger
#

yeah

pale vector
#

try printing rate

odd dagger
#

ok

pallid micaBOT
#

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

odd dagger
#

i want to make it 0 for a "smooth deleting"

pale vector
#

wait are you trying to disable the vfx

odd dagger
#

but if i destroy it

pale vector
#

you can just use emit....

odd dagger
#

it looks weird

#

it is disabled

pale vector
#

can you sent a video?

odd dagger
#

yeah

#

what

#

.mkv

#

lol

#

i made a copy of the game with the GetBoundsInBox so if i want to work with different commands

#

i'm testing it on the experience itself

#

yeah it is bugged there too

pale vector
#

i think the vfx is not dissapearing cuz of your two checks up there

odd dagger
#

the thing is

#

when i change it

#

on the vfx properties

#

it works perfectly

#

like if i change the emission rate on vfx

#

it changes

pale vector
#

try to set the rate before parenting the vfx to the part

#

it that dont works i dont know what is happening really

odd dagger
#

@pale vector two of them are created

#

and its only on the first time

#

i think that

#

when i change the rate

#

vfx is duplicated

#

so thats why it changes

#

probably the same reason for kokusen explosion is duplicated

#

when you change a Clone() property, it creates another clone with these properties

pale vector
#

wait its making two vfxs at the same time or you used it 2 times?

odd dagger
#

the first option

#

i used it 1 time

#

this applies for both part and particleemitter

pale vector
#

did you hit 2 characters?

odd dagger
#

no

#

wait

#

i think i did

#

yeah i did

#

but when i hit only one, two vfx are created

#

@pale vector

pale vector
#

the particle is also cloned?

odd dagger
#

one vfx is enabled

#

the other one isnt

pale vector
#

ohhh so thats why its not changing the rate

#

they have the same name

odd dagger
#

probably because this happens

#

one of them has 1 rate

pale vector
#

the code does not know which one to change

odd dagger
#

the other one has 10

#

the same that isnt enabled

#

is 1 rate

#

and the same that IS enabled is rate 10

#

but in replicated storage, there is only one vfx

#

why is vfx being duplicated

pale vector
#

send your code

odd dagger
#

ok

#

the exists thing made the script stop creating two parts

pallid micaBOT
#

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

odd dagger
#

but vfx is still duplicated

pale vector
#

the script that calls this function calls it two times?

odd dagger
#

nah

pale vector
#

maybe its something with the debounces idk

odd dagger
#

no double executon of the function

#

i see

#

@pale vector

#

its because

#

theres 2 copies

#

the one that comes

#

with part

#

and the one that i clone

#

because when you clone a part all its children come too

#

yeah

#

i've got it

pale vector
#

did you fix it?

odd dagger
#

yeah

#

SO

#

new problem

#

i will try to resolve it manually

#

so

#

when i hit multiple players (two on this example), the first one is ragdolled and knockbacked, and when he gets up, the other player is ragdolled

#

but i want to make both players be ragdolled at once, but without multiplying the vfx

pale vector
#

that actually happened in my game too

#

you just need to use task.spawn

odd dagger
#

i think this is because of debounces

#

so i should only apply debounces in vfx

pale vector
odd dagger
#

@pale vector also

#

hitservice is only executed after kokusen explosion

#

and kokusen explosion has a task wait on its end

#

so it is executed in like 1 second

pale vector
#

you cant put a function inside task.wait

odd dagger
#

also i'm getting lunch so i may be afk sometime

#

oh

#

ok

#

@pale vector

#

yeah i did this to resolve the problem

#

but it didnt work

pale vector
#

sorry i meant task.wait

odd dagger
#

coolguy

#

@pale vector so

#

hitservice and kokusenexplosion both have a wait inside of their functions

pale vector
#

what?

odd dagger
#

lemme show

#

kokusenexplosion

#

when i execute it

#

it will wait this time

#

before the rest of the script is executed

#

so if i execute kokusenexplosion before hitservice, then hitservice will be executed only after kokusenexplosion waited duration + .5

#

and inside hitservice

#

we have this

#

that works on the same way

#

@pale vector

pale vector
#

so you're running both of them at the same time?

odd dagger
#

i think i cant use spawn() with modules

pale vector
#

also why did you put a bool value inside a wait()

odd dagger
#

i mean when it was destroyed

#

i could put knockbackduration tho

#

when using task.spawn

#

oh

#

got it