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.
#issues with firing mechanism
45 messages · Page 1 of 1 (latest)
-- 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)
wdym
click the fireball model
ok
yes, it is sphere
honestly if you are working with projectiles dont use models
it didnt damage?
it fires when i hit e, instead of selecting the spell and then waiting to fire until i click. and it did no damage
alright so the reason it did no damage is models dont have a touched event
set it to the primarypart which is your sphere
set a touched event to the primary?
also, it doesnt despawn after 5 seconds like it should
change fireball.Touched to fireball.PrimaryPart.Touched
dont you have your output open roblox should already be pointing out these errors
i do have output but i didnt see that
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"
change which one
the line where you set the velocity
also, even after unequipping the wand, it still shoots when i click.
sorry Im on mobile
its ok
also change Mouse.Button1Down to tool.Activated
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!!!
ah I was afk, turns out you solved it on your own