Hello,
I have a new game which I want to have a fireball weapon in it, but the fireball isn’t launching when I test it.
Here is the code I used:
local basedmg = 25
local cd = 15
local speed = 5
local en = true
script.Parent.Activated:Connect(function()
if en then
en = false
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local mousepos = script.GetMousePos:InvokeClient(player)
local targetpos = mousepos.p
local handle = script.Parent.Handle
local fireball = handle:Clone()
fireball.Parent = workspace
fireball.Name = 'Fireball'
fireball.Launch:Play()
handle.FireParticle.Enabled = false
handle.Transparency = 1
local lv = Instance.new('LinearVelocity')
lv.VectorVelocity = (mousepos.p - fireball.Position).Unit*speed
lv.MaxAxesForce = Vector3.new(math.huge, math.huge, math.huge)
lv.Parent = fireball
lv.Attachment0 = Instance.new('Attachment', fireball)
script.Activated:FireClient(player, cd) -- This is for the cooldown GUI
fireball.Touched:Connect(function(hit)
fireball.Impact:Play()
if hit.Parent ~= player.Character then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
hit.Parent.Humanoid:TakeDamage(basedmg)
for _, i in pairs(fireball.BurnFX:GetChildren()) do -- This has a folder of the sounds and damage script
i.Parent = hit.Parent
if i.ClassName == 'Script' then -- The script deals burn damage
i.Enabled = true
end
end
fireball:Destroy()
end
else
fireball:Destroy()
end
end)
wait(cd)
en = true
handle.FireParticle.Enabled = true
handle.Transparency = 0.4
end
end)
The problems:
- There is no object in the Workspace called “Fireball”
- The Linear Velocity (called as
lv
) is not being added to the fireball - The cooldown GUI shows up
- The handle re-appears in my hand
- The
en
variable is not the problem; the script just does not parent the clone to the Workspace.
What is supposed to happen:
Upon activation, if the tool is not on cooldown, it will get the player’s mouse position (the target Vector3), clone the Handle, place it into the Workspace, then make the original fireball (the tool) invisible. It then should play a sound and create a LinearVelocity aimed at the target position (mouse pos) at a speed of “speed”. It then activates the cooldown GUI for the user. It waits for the fireball to be touched by somebody that is a player but not the launcher. Lastly, it waits the rest of the cooldown then makes the code enabled again for reuse.
I don’t want a whole script re-wording the code, I just want to know if there are any problems with this code and what they are.
Thank you for your help!
Have a great day