Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Fireball will not work and goes anchored at random times?

Asked by 6 years ago

I shoot my FireBall with Q and it goes foward and it's fine but when I spam it, it gets anchored but when it gets unanchored it sometimes doesn't do it and it is stuck on a line or something..

I am using "Play" not "Run" in studio I am using a LocalScript and a Script that is the damage inside the LocalScript I want my script to be able to be charged by holding Q and when released, gets shot foward

Of course, here is the script-

wait(0.5) Player = game.Players.LocalPlayer Mouse = Player:GetMouse() Character = Player.Character Enabled = true ButtonDown = true

local UserInputService = game:GetService("UserInputService") game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)

if input.KeyCode == Enum.KeyCode.Q then
    if Enabled == false then return end 

Enabled = false 

BV = Instance.new("BodyVelocity")

 x = Instance.new("Part") 

 a = Instance.new("ParticleEmitter")

BP = Instance.new("BodyPosition", Character.HumanoidRootPart)

BG = Instance.new("BodyGyro", Character.HumanoidRootPart)


S = script["Damage"]:clone()

S.Parent = x
S.Disabled = true
x.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0,0,0)


local Pos = Mouse.Hit.p

BG.D = 100

BG.maxTorque = Vector3.new(math.huge, math.huge, math.huge)

BG.cframe = CFrame.new(Player.Character.HumanoidRootPart.Position, Pos)

BP.Position = Player.Character.HumanoidRootPart.Position

BP.maxForce = Vector3.new(math.huge, math.huge, math.huge)

local Color1 = Color3.new(1,0,0)
local Color2 = Color3.new(1,1,0)
local keypoints = {}

x.Shape = "Ball"

x.Material = "SmoothPlastic"

x.Parent = Character

x.Transparency = 1

x.CanCollide = false

x.Orientation = Vector3.new(-90, 0, 0)
a.Parent = x

BV.maxForce = Vector3.new(math.huge, math.huge, math.huge)

BV.velocity = Character.HumanoidRootPart.CFrame.lookVector*100

BV.Parent = x

a.Color = ColorSequence.new(Color1,Color2,Color1)

a.LightEmission = 1

a.LightInfluence = 1

table.insert(keypoints, NumberSequenceKeypoint.new(0, 6.94, 0))

table.insert(keypoints, NumberSequenceKeypoint.new(0.422, 2.19, 0))

table.insert(keypoints, NumberSequenceKeypoint.new(1, 0, 0))

local multiValueSequence = NumberSequence.new(keypoints)

a.Size = multiValueSequence

a.Rate = 1000

a.Rotation = NumberRange.new(1000)

a.RotSpeed = NumberRange.new(1000)

a.Speed = NumberRange.new(10)

a.EmissionDirection = "Bottom"

a.Lifetime = NumberRange.new(1)

a.Texture = "rbxassetid://341300088"

x.Anchored = true

UserInputService = game:GetService("UserInputService")

UserInputService.InputEnded:Connect(function(input)

if ButtonDown == true then

if input.KeyCode == Enum.KeyCode.Q then 

    ButtonDown = false

    S.Disabled = false

    x.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3)

    x.Anchored = false


    BP:Destroy()        
BG:Destroy()

end

while ButtonDown == false do wait(5)

Enabled = true


x:Destroy() 
ButtonDown = true

end

end end) end

end)

0
Wait so what happens exactly when you spam q? AnAnonymousDeveloper 77 — 6y
0
What happens is that at random times it gets anchored and stays there and sometimes it works Firasho 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Ah i think its because your scripting isnt expecting their to be more than 1 "X"

So when you run the code the first bit is working fine (I Pressume) then it fires forward correctly (again im pressuming). So when you have fired it basically this is whats happening

X is created

X is fired

New X is created over writing old X

Old X gets stuck because it was never destroyed The New X should be destroyed because of the variable change

So what you need to do is in the Input function you should have a

repeat wait until ButtonDown = false

then once the wait has ened there should be the code to fire the ball.

im awful at explaining. if you have specific problems with my answer let me know in the comments and ill answer them ~ AnAnonymousDeveloper

0
I tried it and what happened is that the fireball stayed there and kept waiting until the buttondown was false but it never got to it because it kept waiting? Firasho 2 — 6y
0
Nevermind, thank you! You have solved my problem! Firasho 2 — 6y
Ad

Answer this question