#issues with firing mechanism

45 messages · Page 1 of 1 (latest)

gaunt vector
#

So, i tried creating a wand tool, that would, when I hit e, select the Fireball spell from replicatedstorage, and then fire upon clicking. It seems to fire upon hitting e, but I have bigger issues. It doesnt "fire" them. The fireball model for the spell is in replicated, and it has a sphere in it. The sphere should shoot when I click after hitting e, right? Nope. it just spawns all the spheres at one location on the map. Screenshot atatched and script below. *(ignore most of the --text, it is just to let me know what stuff does incase I forget about the project for a while. For some reason, the script sent in 2 messages, wouldnt allow 1.

#

-- Inside the WandScript

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local selectedSpell = nil

local function selectSpell(spellName)
selectedSpell = spellName
print("Selected Spell:", selectedSpell) -- Debugging line
end

local function fireSpell()
if selectedSpell then
print("Firing Spell:", selectedSpell) -- Debugging line

    local fireballModel = game.ReplicatedStorage:FindFirstChild(selectedSpell)

    if fireballModel and fireballModel:IsA("Model") then
        print("Found Fireball model:", fireballModel.Name)  -- Debugging line

        local fireball = fireballModel:Clone()
        fireball.Parent = workspace

        local wandPosition = tool.Handle.Position
        local direction = (mouse.Hit.p - wandPosition).unit
        local velocity = direction * 500  -- Adjust the speed as needed
#

-- Set the initial position of the fireball at the wand
local initialPosition = wandPosition + direction * fireball.PrimaryPart.Size.Z * 0.5
fireball:SetPrimaryPartCFrame(CFrame.new(initialPosition))
fireball:SetPrimaryPartCFrame(fireball:GetPrimaryPartCFrame() * CFrame.new(0,0,-5))
fireball.PrimaryPart.Velocity = velocity -- Use the velocity property of the primary part

        fireball.Touched:Connect(function(hit)
            if hit:IsA("Player") then
                hit:TakeDamage(10)  -- Adjust the damage as needed
            end
            fireball:Destroy()
        end)

        spawn(function()
            wait(5)  -- Adjust the time before disappearing as needed
            if fireball:IsA("Model") and fireball.Parent then
                fireball:Destroy()
            end
        end)
    else
        print("Fireball not found in ReplicatedStorage. Selected Spell:", selectedSpell)  -- Debugging line
    end
end

end

mouse.KeyDown:Connect(function(key)
if key:lower() == "e" then
-- Pressing "E" every time selects the Fireball spell and immediately fires it with a click
selectSpell("Fireball") -- Assuming the tool in ReplicatedStorage is named "Fireball"
fireSpell()
end
end)

little depot
#

check if you actually set the primary part of the model

#

in replicated storage

gaunt vector
#

wdym

little depot
#

click the fireball model

gaunt vector
#

ok

little depot
#

go to properties

#

did you set the primary part

gaunt vector
#

yes, it is sphere

little depot
#

honestly if you are working with projectiles dont use models

gaunt vector
#

that worked. it launched

#

but

little depot
#

it didnt damage?

gaunt vector
#

it fires when i hit e, instead of selecting the spell and then waiting to fire until i click. and it did no damage

little depot
#

alright so the reason it did no damage is models dont have a touched event

#

set it to the primarypart which is your sphere

gaunt vector
#

set a touched event to the primary?

#

also, it doesnt despawn after 5 seconds like it should

little depot
#

change fireball.Touched to fireball.PrimaryPart.Touched

#

dont you have your output open roblox should already be pointing out these errors

gaunt vector
#

i do have output but i didnt see that

little depot
#

is it working rn

#

the spell

gaunt vector
#

no

#

heres my current code, and its just dropping again, even with primary part set to Sphere

#
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local selectedSpell = nil

local function selectSpell(spellName)
    selectedSpell = spellName
    print("Selected Spell:", selectedSpell)  -- Debugging line
end

local function fireSpell()
    if selectedSpell then
        print("Firing Spell:", selectedSpell)  -- Debugging line

        local fireballModel = game.ReplicatedStorage:FindFirstChild(selectedSpell)

        if fireballModel and fireballModel:IsA("Model") then
            print("Found Fireball model:", fireballModel.Name)  -- Debugging line

            local fireball = fireballModel:Clone()
            fireball.Parent = workspace

            local wandPosition = tool.Handle.Position
            local direction = (mouse.Hit.p - wandPosition).unit
            local velocity = direction * 50  -- Adjust the speed as needed

            fireball:SetPrimaryPartCFrame(CFrame.new(wandPosition))  -- Set initial position
            fireball.Velocity = velocity  -- Use the model's velocity property

            fireball.Touched:Connect(function(hit)
                if hit:IsA("Player") then
                    hit:TakeDamage(10)  -- Adjust the damage as needed
                end
                fireball:Destroy()
            end)

            spawn(function()
                wait(5)  -- Adjust the time before disappearing as needed
                if fireball:IsA("Model") and fireball.Parent then
                    fireball:Destroy()
                end
            end)
        else
            print("Fireball not found in ReplicatedStorage. Selected Spell:", selectedSpell)  -- Debugging line
        end
    end
end

mouse.Button1Down:Connect(fireSpell)

mouse.KeyDown:Connect(function(key)
    if key:lower() == "e" then
        selectSpell("Fireball")  -- Assuming the tool in ReplicatedStorage is named "Fireball"
    end
end)
#

heres the output: Velocity is not a valid member of Model "Workspace.Fireball"

little depot
#

models dont have velocity

#

change it to fireball.PrimaryPart

gaunt vector
#

change which one

little depot
#

the line where you set the velocity

gaunt vector
#

also, even after unequipping the wand, it still shoots when i click.

little depot
#

sorry Im on mobile

gaunt vector
#

its ok

little depot
#

also change Mouse.Button1Down to tool.Activated

gaunt vector
#

so now, when i fire, it just dissapears after showing upon the wand for a split second instead of firing...

#

sorry for how much i need help.

#

it doesnt like fly off the wand

#

just blips

#

nvm, go that fixed, but how about the fact that it does no damage??

#

FIXED IT

#

Thank you for ll the help Veulem!!!

little depot
#

ah I was afk, turns out you solved it on your own