#(SOLVED) Script only plays one time and gives me an error

1 messages · Page 1 of 1 (latest)

summer walrus
#

.

#

local Remote = game.ReplicatedStorage.FrontDash

local UIS = game:GetService("UserInputService")
local debounce = false
local humRP = game.Players.LocalPlayer.Character.HumanoidRootPart
local character = game.Players.LocalPlayer.Character
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if debounce == true then return end
if Input.KeyCode == Enum.KeyCode.Q then
debounce = true
Remote:FireServer()
local bv = Instance.new("BodyVelocity")
local lookDirection = character.PrimaryPart.CFrame.LookVector
local strength = 40

    local knockback = lookDirection * strength
    while true do
        wait()
        bv.MaxForce = Vector3.new(math.huge,0,math.huge)
        bv.P = 50000
        bv.Velocity = knockback
        bv.Parent = humRP
        game.Debris:AddItem(bv,0.8)
    end
    wait(3)
    debounce = false
end

end)

#

If anyone knows why this is happening

#

lmk

cedar dock
#
local Remote = game.ReplicatedStorage.FrontDash

local UIS = game:GetService("UserInputService")
local debounce = false
local humRP = game.Players.LocalPlayer.Character.HumanoidRootPart
local character = game.Players.LocalPlayer.Character
UIS.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end
    if debounce == true then return end
    if Input.KeyCode == Enum.KeyCode.Q then
        debounce = true
        Remote:FireServer()
        local bv = Instance.new("BodyVelocity")
        local lookDirection = character.PrimaryPart.CFrame.LookVector
        local strength = 40

        local knockback = lookDirection * strength
        while true do
            wait()
            bv.MaxForce = Vector3.new(math.huge,0,math.huge)
            bv.P = 50000
            bv.Velocity = knockback
            bv.Parent = humRP
            game.Debris:AddItem(bv,0.8)
        end
        wait(3)
        debounce = false
    end
end)```
summer walrus
#

o

#

how do u send it like that

cedar dock
#

local Remote = game.ReplicatedStorage.FrontDash

local UIS = game:GetService("UserInputService")
local debounce = false
local humRP = game.Players.LocalPlayer.Character.HumanoidRootPart
local character = game.Players.LocalPlayer.Character
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if debounce == true then return end
if Input.KeyCode == Enum.KeyCode.Q then
debounce = true
Remote:FireServer()
local bv = Instance.new("BodyVelocity")
local lookDirection = character.PrimaryPart.CFrame.LookVector
local strength = 40

    local knockback = lookDirection * strength
    while true do
        wait()
        bv.MaxForce = Vector3.new(math.huge,0,math.huge)
        bv.P = 50000
        bv.Velocity = knockback
        bv.Parent = humRP
        game.Debris:AddItem(bv,0.8)
       wait(3)
    debounce = false
    end
  end

end)

cedar dock
#

and add do it like 3 `lua
next line code

#

to add code stuff

summer walrus
#

''' aa ''

cedar dock
#
print("yes")```
#

like this

cedar dock
#

its above tab

summer walrus
#

yo

cedar dock
#

i didnt look at entire code but it might fix

summer walrus
#

the loop's purpose was to make a smooth turn on the body velocity

#

depending on the players look direction

#

it does it one time

#

but then gives me a error that body velocity doesnt exist

cedar dock
#

OH

#

the issue is

#

you are using a infinite loop

summer walrus
cedar dock
#

and then doing code after that

#

debounce wont ever be false

#

as the code in the while loop runs forever

summer walrus
#

ohhh

#

waitt that makes sense

cedar dock
#
  while true do
            wait()
            bv.MaxForce = Vector3.new(math.huge,0,math.huge)
            bv.P = 50000
            bv.Velocity = knockback
            bv.Parent = humRP
            game.Debris:AddItem(bv,0.8)
        end```
#

this runs forever

#

never stops

#

thats why

#

nothing after it ever runs

summer walrus
#

so i gotta break it when char:FindFirstChild("bv") is false

#

dwag that makes sense

#

let me try

cedar dock
#

you can do it like

#

that

#

break it when its false

#

while char:FindFirstChild("bv") do
..........
end

cedar dock
summer walrus
#

lemme try

#

loading rn

#

if it works ima be happy af

summer walrus
#

ill try while bv do

summer walrus
#

the bv gets into char in the loop

cedar dock
summer walrus
#

yea lmao

#

i forgor

#

same thing as with the while tru

misty gardenBOT
#

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

summer walrus
#

true

cedar dock
#

then wont it be

#

hrp:FindFirstChild("bv")

#

not char

#

i mean

#

it can just go deeper

#

to hrp

#

but hrp might be better for performance

summer walrus
#

yea i use hrp

#

same thing as with the while true loop bruu

cedar dock
#

try tho

cedar dock
summer walrus
#

wait

#

does game.Debris:Additem delete

#

the bv?

cedar dock
#

whats bv anyway

summer walrus
#

body velocity

#

its a dash script which turns with the players camera

cedar dock
#

whats the error

cedar dock
#

that might be the problem

#

it deletes bv

#

then you try to reparent it

#

if you delete something then try to reparent it

summer walrus
#

OH

cedar dock
#

it sends that error

#

i forgot that lol

#

i read that somewhere in dev forum

#

😅

summer walrus
#

WAIT RIGHT

#

DUDE UR SMART AF

#

1 SEC

#

ILL BREAK IT WHEN BV FALSE

cedar dock
#

do that before reparenting

#

else

#

its gonna

#

send that error

summer walrus
#

do i use findfirstchild?

cedar dock
#

for what

summer walrus
#

cz if i use it before the parent its not gonna be in the player

#

to break it

cedar dock
#

oh also

#

dont just use wait()

#

add a value

#

else its gonna be different

summer walrus
#

o

cedar dock
#

like very low difference

#

but its gonna be difference

#

for some machines

summer walrus
#

ill make it 0.001 then

cedar dock
#

its gonna be like of 0.01 or sum

#

but yeah

#

difference

summer walrus
#

0.01 also works

#

wait

#

how do i check if the bv exists

#

i do if bv then?

cedar dock
#

wdym

summer walrus
#

like how to check if its destroyed

cedar dock
#

i never did that so idk if if bv will work

#

you can make a variable tho

#

like

#

outside while loop make

local bvdestroyed = false```
#

turn it on after the adddebris

#

and check

#

that is it on

#

or off

summer walrus
#

debris doesn't make it wait

#

its gonna trigger it after 0.01

#

seconds

cedar dock
#

0.8 is like a very small number anyway

#

idk tho

summer walrus
#

lemme try sum

cedar dock
#

@summer walrus wait

#

you can instead of making varibale do like

summer walrus
#

WAIT

cedar dock
#

if bv.Parent == nil

summer walrus
#

o

cedar dock
#

if its

#

parent is nil

#

and if thats nil

#

you either didnt assign a parent

#

or its destroyed

summer walrus
#

heres the error btw

cedar dock
#

wait no you declare its parent in the loop anyway

summer walrus
cedar dock
#

def

#

its because

#

its deleted

#

cuz its parent is null

summer walrus
#

oh

cedar dock
#

aka bv is destroyed so you cant

#

reparent it

#

cuz it doesnt exist

#

:/

summer walrus
#

is destroyed/deleted, It will always return nil. So just check if it is nil within an if statement.

#

checked on forum

cedar dock
#

yeah didnt i say that

#

:/

summer walrus
#

so if i do "if bv = nil" then break?

cedar dock
#

Now i have become forum , Crator of worlds

summer walrus
#

itll work?

cedar dock
#

no

#

if bv.parent = nil

#

wait

#

will bv be nil

#

or parent be nil

#

actually bv will be nil

summer walrus
#

bv

cedar dock
#

i think

#

you can try

#

that will work

#

cuz bv will be nil too

#

cant you just do

while bv ~= nil do
            wait()
            bv.MaxForce = Vector3.new(math.huge,0,math.huge)
            bv.P = 50000
            bv.Velocity = knockback
            bv.Parent = humRP
            game.Debris:AddItem(bv,0.8)
        end```
summer walrus
#

o

cedar dock
#

that looks better

summer walrus
#

yea

cedar dock
#

and does the same thing

#

@summer walrus does it work

summer walrus
#

i was rewriting

#

how do u do this script thing i still dont get it

#

''' . '''

cedar dock
#

its like

#
print("hi")
summer walrus
#

ohh

#

'''lua
print("me")
'''

cedar dock
#
print("hiii")```
#

this will work too

#

tihis will

cedar dock
#

` is above tab

summer walrus
#

oh

#
while bv ~= nil do
            local lookDirection = character.PrimaryPart.CFrame.LookVector
            local strength = 40
            local knockback = lookDirection * strength
                wait()
                bv.MaxForce = Vector3.new(math.huge,0,math.huge)
                bv.P = 50000
                bv.Velocity = knockback
                bv.Parent = humRP
                game.Debris:AddItem(bv,0.8)
            end```
#

ohhh

#

it gives the same error

cedar dock
#

its called a backtick for some reason

#

GRR

summer walrus
#

dude i think bv doesnt get turned nill

misty gardenBOT
#

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

cedar dock
#

to like

#

nvm

#

that wont work

cedar dock
summer walrus
#

ohhh

#

it only sets parts to nil

#

for instances its different

cedar dock
#

try doing it and removing game.Debris:AddItem(bv,0.8) once

cedar dock
#

try

#

bv.parent

#

actually no

#

its nil at start too

#

isnt it

summer walrus
#

Currently, the only way to absolutely check if a part is destroyed is by trying to access one of these locked-down properties in a pcall and see what the error is. This is not sufficient

#

i dont get it

#

lmao

cedar dock
#

and print(bv.parent, "2") after the while

#

tell me what it prints on both

summer walrus
#

k

#

@cedar dock

#

cant i

#

parent it befoer

#

wit

#

wait

#

what if i parent it before the while tru

#

and add the debris before aswell

#

OK GOOD THE ERROR IS GONE

#

NOW WHEN ITS FINISHED ITS PARENT IS NIL

#

it says in the print

#

now i can do ```lua
if bv.Parent == nil then
break
end

#

IT WORKS

#

@cedar dock

#

LETS GOOO

#

IT WORKS LOVE U MAYN

#
local Remote = game.ReplicatedStorage.FrontDash

local UIS = game:GetService("UserInputService")
local debounce = false
local humRP = game.Players.LocalPlayer.Character.HumanoidRootPart
local character = game.Players.LocalPlayer.Character
UIS.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end
    if debounce == true then return end
    if Input.KeyCode == Enum.KeyCode.Q then
        debounce = true
        Remote:FireServer()
        local bv = Instance.new("BodyVelocity")
        bv.Parent = humRP
        game.Debris:AddItem(bv,0.8)
        while bv ~= nil do
            local lookDirection = character.PrimaryPart.CFrame.LookVector
            local strength = 40
            local knockback = lookDirection * strength
                wait()
                bv.MaxForce = Vector3.new(math.huge,0,math.huge)
                bv.P = 50000
                bv.Velocity = knockback
                if bv.Parent == nil then
                    break
                end
            end
        wait(3)
        debounce = false
    end
end)
cedar dock
#

gg

summer walrus
#

(SOLVED) Script only plays one time and gives me an error

cedar dock
#

oh if bv,parent == nil

summer walrus
#

before the loop

#

bv.Parent = humRP

#

and it worked