Due to the fact that i cannot run the OnServerEvent with local script how can i make it so fireball fires in direction of mouse?
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Fire = Instance.new("RemoteEvent", ReplicatedStorage) Fire.Name = "FireBall" local plr = game:GetService([[Players]]).LocalPlayer local mouse = plr:GetMouse() local Char = plr.Character or plr.CharacterAdded:wait() local lefthand = Char.LeftHand Fire.OnServerEvent:connect(function(Player, Debounce) local Char = Player.Character or Player.CharacterAdded:wait() Debounce = true local Fireball = Instance.new("Part") Fireball.Name = "FireBall" Fireball.Shape = Enum.PartType.Ball Fireball.Size = Vector3.new(3,3,3) Fireball.Material = Enum.Material.Neon Fireball.CanCollide = false Fireball.Parent = Char Fireball.CFrame = Char.HumanoidRootPart.CFrame*CFrame.new(2,0,-6) Fireball.BrickColor = BrickColor.new("Bright orange") local BV = Instance.new([[BodyVelocity]], Fireball) BV.Velocity = Vector3.new(mouse.Hit.lookVector * 90) BV.MaxForce = Vector3.new(lefthand.CFrame.lookVector, 5, 0) --oof local dmg = script.Dmg:Clone() dmg.Parent = Fireball dmg.Disabled = false wait(0.5) dmg:Destroy() wait(4) Debounce = false Fireball:Destroy() end)
LocalPlayer
, Mouse
from a Script
. Since you need the Hit
of the mouse, simply send it as a parameter.local ReplicatedStorage = game:GetService("ReplicatedStorage") local Fire = Instance.new("RemoteEvent") -- parent argument deprecated Fire.Name = "FireBall" Fire.Parent = ReplicatedStorage -- parent LAST Fire.OnServerEvent:Connect(function(Player, Hit, Debounce) -- connect is deprecated, use Connect -- Hit will be the mouse Hit local Char = Player.Character or Player.CharacterAdded:Wait() -- :wait() is deprecated local lefthand = Char.LeftHand Debounce = true local Fireball = Instance.new("Part") Fireball.Name = "FireBall" Fireball.Shape = Enum.PartType.Ball Fireball.Size = Vector3.new(3,3,3) Fireball.Material = Enum.Material.Neon Fireball.CanCollide = false Fireball.CFrame = Char:GetPrimaryPartCFrame()*CFrame.new(2,0,-6) Fireball.BrickColor = BrickColor.new("Bright orange") Fireball.Parent = Char local BV = Instance.new("BodyVelocity") BV.Velocity = Hit.LookVector*90 -- LookVector is already a Vector3 BV.MaxForce = Vector3.new(lefthand.CFrame.LookVector.X, 5, 0) -- LookVector is the vector, the X property is the X coordinates of the vector BV.Parent = Fireball local dmg = script.Dmg:Clone() dmg.Parent = Fireball dmg.Disabled = false wait(0.5) dmg:Destroy() wait(4) Debounce = false Fireball:Destroy() end)
-- somewhere in a localscript Fire:FireServer(mouse.Hit, Debounce) -- Do NOT pass the player!
What's happening here is that you seem to be using LocalPlayer which is only accessible to the client. A possible fix would be to run a code in a local script telling the server to create a fireball.