New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

My Fireball wont shoot at my mouse position?

Asked by 1 year ago
Edited by User#24403 1 year ago

so i was watching a YouTube video on how to make a Fireball shoot out but it shot out and forward from your torso, so i tried to edit it and make it shoot at the mouse position as this

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local RemoteEvent = game.Workspace.Fired

local UIS = game:GetService("UserInputService")

local Debounce = false


    if Debounce == true then return end



That's my FireBall script in my StarterPack

and this is my FireBall Event Script

game.Workspace.Fired.OnServerEvent:Connect(function(Player, Debounce)
    local Character = Player.Character or Player.CharacterAdded:wait()
    Debounce = true
    local Mouse = Player:GetMouse()
    local mH = Mouse.Hit 
    local Fireball ='Part') 
    Fireball.Shape = Enum.PartType.Ball 
    Fireball.BrickColor ='Deep orange')
    Fireball.Transparency = '0.5'
    Fireball.Size =,2,2)
    Fireball.CanCollide = false
    Fireball.Material = Enum.Material.Neon
    Fireball.Parent = Character
    Fireball.CFrame = Character.Torso.CFrame*,1,-6)
    local BV ="BodyVelocity")
    BV.MaxForce =,math.huge,math.huge) 
    BV.Velocity = Character.mH.p.CFrame.lookVector*100
    BV.Parent = Fireball
    Debounce = false 

could you please help me to find why this error shows up

    11:29:06.292 - Workspace.Fired Event:5: attempt to index local 'Mouse' (a nil value)

11:29:06.293 - Stack Begin

11:29:06.295 - Script 'Workspace.Fired Event', Line 5

11:29:06.296 - Stack End

I Also have a Fired RemoteEvent in my workspace

ps: im learning to code lua and a game with my friend from watching tutorials and getting to know what specific stuff does, and with things like this. iv'e never asked a question until now but is that a good way to learn to code or should i try a different approach

That's what i did?.. Coocooman001 0 — 1y
You used *blockquotes* to format the code. I've edited your question to format the code in a *code* block. It is expected that you do this yourself next time. User#24403 26 — 1y

1 answer

Log in to vote
Answered by 1 year ago

Side note; it is against the rules to post code that is not your own attempt. I will give you a pass this time, since this is your first question on the site.

The mouse is created client side, therefore the server cannot see it.

Player:GetMouse returns nil on the server side, because the mouse instance is created on the client. It does not make sense for the server to handle mouse logic.

If the server needs mouse.Hit, why not send it to the server directly?

lua RemoteEvent:FireServer(mouse.Hit);

Mouse events have been superseded by UserInputService and ContextActionService events/functions.

You had declared UIS but never used it. Why not use it?

In addition, remote events/functions should always be in ReplicatedStorage, unless they specifically need to be elsewhere, like a Tool. I don't see a need for it in Workspace in your situation.

```lua local UserInputService = game:GetService("UserInputService"); local ReplicatedStorage = game:GetService("ReplicatedStorage"); local Players = game:GetService("Players");

local client = Players.LocalPlayer; local cursor = client:GetMouse(); local canShoot = true;

UserInputService.InputBegan:Connect(function(input, gameProcessed) --[[ /* input is the inputObject, which contains properties like UserInputType, KeyCode, ect. gameProcessed is a boolean that is true if the event fired because of interaction with the game engine, like typing in a textbox, e.g. chatting, or if you click a gui button */ --]]

if (gameProcessed or not rawequal(input.UserInputType.Name, "MouseButton1") or not canShoot) then
    return; --// end function since interacted with engine, or they did *not* press left mouse button, or they cannot shoot

canShoot = false;
ReplicatedStorage.Fired:FireServer(cursor.Hit.Position); --// sending only the position; you don't need the whole cframe or do you ???
canShoot = true;

end); ```

And on the server side...

```lua local ReplicatedStorage = game:GetService("ReplicatedStorage");

--// constants local BALL_SIZE =, 2, 2); local MAX_FORCE =, math.huge, math.huge); local BALL_COLOUR ="Deep orange");

ReplicatedStorage.Fired.OnServerEvent:Connect(function(client, position) local character = Player.Character; local fireball ="Part"); fireball.Shape = Enum.PartType.Ball ; fireball.BrickColor = BALL_COLOUR; fireball.Transparency = 0.5; --// doesn't need to be string fireball.Size = BALL_SIZE; fireball.CanCollide = false; fireball.Material = Enum.Material.Neon; fireball.CFrame = character.Torso.CFrame*, 1, -6); fireball.Parent = character;

local bodyVelocity ="BodyVelocity");
bodyVelocity.MaxForce = MAX_FORCE;
bodyVelocity.Velocity = character.HumanoidRootPart.CFrame.LookVector*100;
bodyVelocity.Parent = fireball;

end); ```


Answer this question