Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

"attempt to index local 'mouse' (a nil value)"?

Asked by 6 years ago

Hi. A local script inside a tool fires a RemoteEvent also placed inside the tool when activated with the arguments of:

firere:FireServer(mouse, hum, handle, damage, flyoffvals)

The script that runs when RemoteEvent is fired looks like this:

local firere = script.Parent:WaitForChild("Fire")

firere.OnServerEvent:connect(function(player, mouse, hum, handle, damage, flyoffvals)

    local fb = handle:Clone()
    fb.Parent = game.Workspace
    fb.Name = "Fireball"
    fb.CFrame = handle.CFrame

    print(player.Name .. "'s fireball was launched!")

    local particle = fb:WaitForChild("ParticleEmitter")

    particle.LockedToPart = false
    particle.Rate = 300

    local bv = Instance.new("BodyVelocity", fb)
    bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    bv.Velocity = mouse.Hit.lookVector * 350

    print(player.Name .. "'s fireball BodyVelocity was created!")

    game.Debris:AddItem(fb, 1.5)

    fb.Touched:connect(function(part)
        local vhum = part.Parent:findFirstChild("Humanoid")
        if vhum and vhum.Health > 0 and vhum ~= hum then
            vhum:TakeDamage(damage)

            for x = 1,10 do
                local cfb = fb:Clone()
                cfb.Parent = game.Workspace
                cfb.Position = fb.Position
                cfb.BodyVelocity.Velocity = Vector3.new(flyoffvals[math.random(1, #flyoffvals)], flyoffvals[math.random(1, #flyoffvals)], flyoffvals[math.random(1, #flyoffvals)])
                game.Debris:AddItem(cfb, 1.5)
            end

            fb:Destroy()

        elseif part.Anchored == true and part.CanCollide == true then
            for x = 1,10 do
                local cfb = fb:Clone()
                cfb.CFrame = fb.CFrame
                cfb.BodyVelocity.Velocity = Vector3.new(flyoffvals[math.random(1, #flyoffvals)], flyoffvals[math.random(1, #flyoffvals)], flyoffvals[math.random(1, #flyoffvals)])
                game.Debris:AddItem(cfb, 1.5)
            end

            fb:Destroy()
        end
    end)
end)

I'm getting the error at line 19. I'm getting the player's mouse using "player:GetMouse()" inside the local script. All help is appreciated very, very much. Thanks :} ~Loughdough

0
I don't see local mouse=game.Players.LocalPlayer:GetMouse() at the top of this script DanzLua 2879 — 6y
0
@DanzLua I said it was in the local script...? Loughdough 291 — 6y
0
@LoughDough its not in a localscript? DanzLua 2879 — 6y
1
That isn't the local script. Actually READ what I said. Someone already answered the question anyways so it doesn't matter. Loughdough 291 — 6y
0
@LoughDough don't be rude to someone who's trying to help you Sadwowow21 57 — 3y

1 answer

Log in to vote
1
Answered by 6 years ago

To the server mouse does not exist. Try just sending the lookVector instead of the mouse.

0
Thanks! Loughdough 291 — 6y
Ad

Answer this question