I am trying to make a projectile when you press a button it sends a fireball. The only thing I need help with is actually sending the fireball. Like CFrames and so on.
I did watch YouTube videos, but it wasn’t that useful for me.
Projectiles are probably 1 of my most personal favorite things to make, especially considering how you want to handle this
For your instance, you want to send a Fireball upon clicking a Button The thing here, is that it depends what “Button” specifically we’re looking at here (ClickDetector, GuiButton, etc)
Once we know what “Button” we’re looking for, then I’ll give an explanation on what to do
Well you’d need to use RemoteEvents, which would be capable of handling client/server transportation
We’d want to send a Fireball to the server-side, and the User Detection from the client
You could potentially do something like this?
--Client Side
local Event = game.ReplicatedStorage:WatiForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, Chatted)
if Chatted then
return
end
if Input.KeyCode == Enum.KeyCode.F then
Event:FireServer() --We're sending this for the server to receive
end
end)
--Server Script inside ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Fireball = game.ServerStorage:WaitForChild("Fireball")
Event.OnServerEvent:Connect(function(Player)
local Clone = Fireball:Clone()
Clone.Parent = workspace
--You can set where you want the fireball to go from, it depends though
end)
I’m sorry I might have given you the wrong idea but I’m trying to make it so it moves I did everything like that already just not the moving part like how far it goes and everything like that.
You still haven’t answered where you want the fireball to fire from though Like do you want it to target towards where the mouse is? Or where the Character is looking?
I’d like to fire where the character is looking/facing. So if the character is facing for example north it will go north, and I like the new avatar lol.
cant you just use a body velocity body mover then have its velocity be the vector formed from the player and the mouse hit. if you want it to go where the player is facing just set the velocity to the look vector ig
velocity is just speed with direction (vector) and to form a vector from 2 points, say A to B its just B-A. Normalize that vector (.Unit) then multiply it by some scalar
The easy approach is by creating a Touched event inside that OnServerEvent you just created (EVENT-CEPTION >:O)
After creating all of your stuff, just add a Touched event that will damage any Humanoid that touches it, you could also create a debounce if the want the Part to only damage you once (Otherwise it’d just either result in instakilling you or majorly damaging you
local FireballDamage = 25
local DB = false
Clone.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if not DB and Player then
local Character = Hit.Parent
DB = true
Character.Humanoid:TakeDamage(FireballDamage)
wait(1)
DB = false
end
end)
--Server Script inside ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Fireball = game.ServerStorage:WaitForChild("Fireball")
local Speed = 80
local Offset = 10
Event.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local Clone = Fireball:Clone()
Clone.Parent = workspace
Clone.Position = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * Offset
local BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = Clone
BodyVel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVel.Velocity = Character.HumanoidRootPart.CFrame.LookVector * Speed
local FireballDamage = 25
local DB = false
Clone.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if not DB and Player then
local Character = Hit.Parent
DB = true
Character.Humanoid:TakeDamage(FireballDamage)
wait(1)
DB = false
end
end)
end)