Fire Ball
LocalScript (StarterPlayerScripts)
local userInput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local FireEvent = ReplicatedStorage:WaitForChild('FireBallEvent')
local function throw(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.E then
FireEvent:FireServer(mouse.Hit.p)
end
end
end
end
userInput.InputBegan:Connect(throw)
Script (ServerScriptService)
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local FireEvent = ReplicatedStorage:WaitForChild('FireBallEvent')
FireEvent.OnServerEvent:Connect(function(player, mousePos)
--Create new object
local fireBall = Instance.new('Part')
local flame = Instance.new('Fire')
local caster = Instance.new('StringValue')
--Caster info
caster.Value = player.Name
caster.Name = 'Caster'
caster.Parent = fireBall
--Flame info
flame.Parent = fireBall
flame.Size = 10
flame.Color = BrickColor.new('Lime green').Color
--Fireball info
fireBall.Name = 'fireBall'
fireBall.Parent = game.Workspace
fireBall.Shape = Enum.PartType.Ball
fireBall.Size = Vector3.new(0.1, 0.1, 0.1)
fireBall.Color = BrickColor.new('Lime green').Color
fireBall.CanCollide = false
--Moving the fireball
local speed = 250
fireBall.CFrame = CFrame.new(player.Character.RightHand.Position, mousePos)
fireBall.Velocity = fireBall.CFrame.lookVector * speed
--Attach damage script
local fireBallScript = game.ServerStorage:FindFirstChild('FireBallDamage'):Clone()
fireBallScript.Parent = fireBall
end)
FireBallDamage (ServerStorage)
local fireBall = script.Parent
local function hit(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid and fireBall.Caster.Value ~= humanoid.Parent.Name then
humanoid:TakeDamage(30)
end
end
game:GetService('Debris'):AddItem(fireBall, 0.75)
fireBall.Touched:Connect(hit)