#touch event makes one enemy makes me lose x18 times
1 messages · Page 1 of 1 (latest)
put some cooldown on it
or make a table that saves the enemy and check to make sure that the same enemy doesnt hit twice
if multiple enemies walks into the base, few of the enemies will not be destroyed and execute the touch script (idk how)
ill just demonstrate rq
wait wha i added task.wait for the touched event kept executing continuously
just putting task.wait doesnt stop the event from firing again
you need debounce
here
** You are now Level 3! **
i put the timer to 10 to uhh
yk
imagine if multitple enemies folded into one place doesnt it just do the bug inside the video
you're applying your debounce too broadly
you have it so that if an enemy touches the brick 10 seconds have to pass before another enemy touching it is valid
you can use a table to track whether an enemy has touched the brick before and that could be your debounce
so for my game you can pick up balls and to make sure players dont fire the OnTouch multiple times i use debounce with a key
local key = player.UserId .. "-" .. trashType
if not debounce[key] then -- if debounce isnt set
debounce[key] = true -- set debounce
local PlayerData = PlayerStore.GetData(player) -- get playerdata
local TrashAmount = PlayerData.trash -- get trash
if TrashAmount >= PlayerData.maxCapacity then -- if their trash is at max
debounce[key] = nil -- Clear debounce immediately if at capacity
return
end
the key has their userID since its unique to the player and then trashType which has 3 different types
this method has worked well for me you could try that, that way it stores the object and player so it wont fire more then once
Okay so ive never heard about pkayerdata or .getdata or anything similar to that i think ill learn what it is first then ill come back here
PlayerData is a variable i made to get the data from my data base
GetData is just a function i made to return a players data
im using profile store by loleris
for what your after you dont need that though, you just need to look into using a debounce
this line here
im confused is it just mean that if debounce == false or debounce == nil??
is that a thing??
how can i do it
yeah just think a little bit more abstract about debounce
create a table
when an enemy touches the brick, check if the enemy is found inside the table
if not insert them in the table and continue
that way the code will only run once for each enemy
are there any examples?
i just asked chatgpt is it what you mean?
So in if statements you can use false or nil
False just means there is a value and it's false
Nil means there is no value
This looks good the idea is
If you just added a debounce with a timer then timing it with the enemies would be hard
So instead you do a debounce but with specific enemies
So if EnemyA touching your part he can not fire it again
But EnemyB is able to immedialty
How you do that is how you have
Stick them in a table if they have
And add a check
i added that deboucne script but it still doesnt work