#(SOLVED) Script only plays one time and gives me an error
1 messages · Page 1 of 1 (latest)
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
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)```
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)
try this
add 3 ` before start and after end of code like this
and add do it like 3 `lua
next line code
to add code stuff
''' aa ''
yo
does this work btw
i didnt look at entire code but it might fix
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
o
and then doing code after that
debounce wont ever be false
as the code in the while loop runs forever
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
so i gotta break it when char:FindFirstChild("bv") is false
dwag that makes sense
let me try
you can do it like
that
break it when its false
while char:FindFirstChild("bv") do
..........
end
i think this might work aswel
this prob wont work cz when i create the bc instance its not in the char yet
ill try while bv do
i mean
i thought it is
the bv gets into char in the loop
as you said this
** You are now Level 2! **
true
it gets into hrp not char right
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
try tho
send the while loop code rq
whats bv anyway
whats the error
oh
that might be the problem
it deletes bv
then you try to reparent it
if you delete something then try to reparent it
OH
do i use findfirstchild?
for what
o
ill make it 0.001 then
wdym
like how to check if its destroyed
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
lemme try sum
WAIT
if bv.Parent == nil
o
that checks
if its
parent is nil
and if thats nil
you either didnt assign a parent
or its destroyed
heres the error btw
wait no you declare its parent in the loop anyway
oh
is destroyed/deleted, It will always return nil. So just check if it is nil within an if statement.
checked on forum
so if i do "if bv = nil" then break?
Now i have become forum , Crator of worlds
itll work?
no
if bv.parent = nil
wait
will bv be nil
or parent be nil
actually bv will be nil
bv
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```
o
that looks better
yea
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
dude i think bv doesnt get turned nill
** You are now Level 3! **
try
to like
nvm
that wont work
send error
try doing it and removing game.Debris:AddItem(bv,0.8) once
😭
try
bv.parent
actually no
its nil at start too
isnt it
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
do print(bv.parent, "1") before the while
and print(bv.parent, "2") after the while
tell me what it prints on both
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)
gg
(SOLVED) Script only plays one time and gives me an error
what did you do to fix
oh if bv,parent == nil
i added the parenting thing
before the loop
bv.Parent = humRP
and it worked