local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FireballEvent = Instance.new("RemoteEvent")
FireballEvent.Name = "FireballEvent"
FireballEvent.Parent = ReplicatedStorage
local CreateExplosion = Instance.new("RemoteFunction")
CreateExplosion.Name = "CreateExplosion"
CreateExplosion.Parent = ReplicatedStorage
local function createExplosion(position)
local explosionPart = Instance.new("Part")
explosionPart.Size = Vector3.new(50, 50, 50)
explosionPart.Position = position
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 0.8
explosionPart.BrickColor = BrickColor.new("Bright red")
explosionPart.Parent = workspace
wait(0.1)
local nearbyParts = workspace:FindPartsInRegion3(
Region3.new(position - Vector3.new(25, 25, 25), position + Vector3.new(25, 25, 25)),
nil
)
for _, part in ipairs(nearbyParts) do
local hitHumanoid = part.Parent:FindFirstChild("Humanoid")
if hitHumanoid and hitHumanoid.Parent:FindFirstChild("NameTag") and hitHumanoid.Parent.NameTag.Text == "Enemy" then
hitHumanoid:TakeDamage(20) -- Adjust the damage amount as needed
end
end
explosionPart:Destroy()
end
CreateExplosion.OnServerInvoke = function(player, position)
createExplosion(position)
end
FireballEvent.OnServerEvent:Connect(function(player, fireballDirection)
local character = player.Character
if character then
local tool = character:FindFirstChild("Fire Staff")
if tool then
local fireballPosition = tool:WaitForChild("Handle").CastPoint.Position
local fireballModel = ReplicatedStorage:FindFirstChild("Fireball")
if fireballModel then
local fireball = fireballModel:Clone()
fireball:SetPrimaryPartCFrame(CFrame.new(fireballPosition))
fireball.Parent = workspace
local fireballDirectionNormalized = fireballDirection
local fireballBodyVelocity = Instance.new("BodyVelocity")
fireballBodyVelocity.Velocity = fireballDirectionNormalized * 30
fireballBodyVelocity.MaxForce = Vector3.new(0, math.huge, 0)
fireballBodyVelocity.Parent = fireball
fireball.Touched:Connect(function(hit)
local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
local hitHumanoid = hit.Parent:FindFirstChild("Humanoid")
if hit:IsA("Part") and (hitHumanoid and hitHumanoid.Health > 0) then
if hitPlayer and hitPlayer == player then
return
end
if hitHumanoid.Parent:FindFirstChild("NameTag") and hitHumanoid.Parent.NameTag.Text == "Enemy" then
hitHumanoid:TakeDamage(10) -- Adjust the damage amount as needed
fireball:Destroy()
-- Request explosion from server
CreateExplosion:InvokeClient(hit.Position)
end
end
end)
end
end
end
end)
that is the server script and this is the local script
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FireballEvent = ReplicatedStorage:WaitForChild("FireballEvent")
local UIS = game:GetService("UserInputService")
local function isFireStaffEquipped(character)
local tool = character:FindFirstChild("Fire Staff")
return tool ~= nil
end
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.Q then
local character = player.Character or player.CharacterAdded:Wait()
if character.Parent.Name == "Characters" and isFireStaffEquipped(character) then
local fireballDirection = character.HumanoidRootPart.CFrame.lookVector
FireballEvent:FireServer(fireballDirection)
print("Fireball event sent to server!")
end
end
end)