#What is happening?

1 messages · Page 1 of 1 (latest)

abstract whale
#

I have some parts with trails on them moving towards the player on the RenderStepped event. I am 'destroying' them when they get close instead of using collision because they are cosmetic only, however something weird is happening with my destroy function. In my 'update' function I do:

if(dist < 1) then
  self:destroy(false)
end

which causes them to behave weird. If I remove this or replace it with self:Destroy() it works how it should (when they get close, they are destroyed). The only reason I'm making my own destroy function is because I want to wait for the trail to expire.

Here is my 'destroy' function:

function ItemStar:destroy(destroyImmediate)
  if not self.part then
    return
  end
    
  if not destroyImmediate then
    self.linearVel.VectorVelocity = Vector3.zero
    self.linearVel:Destroy()
    self.part.Anchored = true
    self.part.Transparency = 0 -- change to 1 after debugging
    wait(2.1)
  end
    
  self.part:Destroy()
end

if I remove the entire "if not destroyImmediate" if statement, this also works.

I've attached a video of what is happening, I think it explains what is happening better than I can with words.

does doing self.linearVel:Destroy() not destroy the linear velocity part? I am updating that in my 'update' function, but I never get any errors in the console.

#

here is my update function, in case it is a problem with that:

function ItemStar:update(deltaTime)
    if not (self.targetPlayer and self.targetPlayer.Character and self.targetPlayer.Character:FindFirstChild("HumanoidRootPart")) then
        return
    end
    
    local targetPos = self.targetPlayer.Character.HumanoidRootPart.Position
    local direction = (targetPos - self.part.Position).Unit
    local dist = (targetPos - self.part.Position).Magnitude

    local newVel = Vector3.new(0, 0, 0)
    self.lifetime += deltaTime
    
    -- moving
    if(self.lifetime < 0.35) then
        newVel = Utils.LerpVelSpecial(self.linearVel.VectorVelocity, Vector3.zero, 0.07, self.decreaseVelProportion)
    else
        local strength = math.min(math.pow(self.lifetime - 0.35, 3), 35) -- smoothing, - 0.35 to offset wait time and 35 is max
        newVel = self.linearVel.VectorVelocity:Lerp(direction * strength, 0.1125)
    end
    
    -- pulling if out of range
    if(dist > 12) then
        local pullVel = direction * (dist / 2) * 3
        newVel = newVel:Lerp(pullVel, 0.02)
    end
    
    self.linearVel.VectorVelocity = newVel
    
    if(dist < 1) then
        self:destroy(false)
    end
end

The part that is causing them to bounce back and fourth is the 'pulling if out of range' section. What I don't understand is, if this function is still being called when RenderStepped happens, why on earth is the 'else' part of the moving if/else statement not working after self:destroy is called? If I remove the call to destroy completely, that behavior does not happen.

#

Also, i remove the elements from the table when they are nil in the RenderStepped function, which calls update on the element when it is not nill or removed.

hybrid stone
#

Can you tell me what you want to achieve? I don't understand

hybrid stone
abstract whale
#

be destroyed, like the second part of the first video

coarse slateBOT
#

studio** You are now Level 1! **studio

abstract whale
#

however i want to wait for the trail to dissapear, so I can't destroy it immediately

hybrid stone
#
if self.Part then task.wait(duration) self.Part:Destroy() end```
abstract whale
#

it also needs to stop moving when reaching the player

#

thats why i have my destroy function

hybrid stone
abstract whale
#

yes

hybrid stone
abstract whale
#

isnt that what im doing by destroying the LinearVelocity part

hybrid stone
#

??

abstract whale
#

shouldnt that now be destroyed and unable to be updated

hybrid stone
#

Disconnecting only works by using :Disconnect() or destroying the part if the connection is tied to an event concerning THAT same part

#

or using :Once() for an auto-disconnecting connection

#

hold on i'll need to take a look at the code again

abstract whale
#

ok i think i understand what you're saying

hybrid stone
#

Where is the connection?

#

script

#

may i see the script of the connection?

abstract whale
#

im not sure what you mean by "the script of the connection"

#

sorry

hybrid stone
#

I want to see the code

abstract whale
#
SpawnEvent.OnClientEvent:Connect(function(targetPlayer, config)
    table.insert(itemStars, ItemStar.new(targetPlayer, targetPlayer.Character.HumanoidRootPart.Position + Vector3.new(0, 5, 0), config))
end)
#

i can't show you the entire thing anymore, i've edited it a lot since posting.

#

well i mean i can but things have changed on it

#

its mostly working now, but i had to increase the distance from 1 to 2.5

#

then it always gets destroyed

hybrid stone
#

are you on studio?

abstract whale
#

yes

hybrid stone
#

can you screenshot it ?

abstract whale
#

screenshot what?

hybrid stone
#

it looks a lot more readable on studio

hybrid stone
abstract whale
hybrid stone
#

even if you edited it

abstract whale
hybrid stone
#

can you jsut invite me to studio so i don't keep asking a lot?

abstract whale
#

umm to be honest i think the problem is mostly solved or averted by new changes. I think im just going to use that task thing you suggested to wait instead of calling wait(2.1), that might be part of the issue.

hybrid stone
#

Oh alright are you happy with it right now?

abstract whale
#

it could be a bit better but nothing's perfect i guess, especially since this is the first time i've ever done anything in roblox studio

coarse slateBOT
#

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

abstract whale
# hybrid stone Oh alright are you happy with it right now?

actually tbh maybe something was wrong with wait(2.1). I converted it to use a task instead after you mentioned it, and now I can set the distance back to 1. Im not sure if this is the actual fix or something else i did along the way fixed it since then haha.

hybrid stone