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)" I already defined Mouse and it still wont work???

Asked by 4 years ago
Edited 4 years ago

While I was coding a magic script, I got an error message that says "19:18:12.082 - ServerScriptService.SuperpowersScript:36: attempt to index local 'Mouse' (a nil value)" but I already defined Mouse

local RS = game:GetService("ReplicatedStorage")
local RemotesFolder = RS:WaitForChild("Remotes")
local DeathBomb = RemotesFolder:FindFirstChild("DeathBomb")
local EffectsFolder = RS:FindFirstChild("Effects")
local BallEffect = EffectsFolder:FindFirstChild("Ball")
local SpikeyEffect = EffectsFolder:FindFirstChild("Spikey")

DeathBomb.OnServerEvent:Connect(function(player)
    local Character = player.Character
    local Mouse = player:GetMouse()
    local Ball1 = BallEffect:Clone()
    local Spikey1 = SpikeyEffect:Clone()
    wait()
    Ball1.Parent = player.Character
    Ball1.Anchored = true
    Ball1.BrickColor = BrickColor.new("Royal purple")
    Ball1.Material = Enum.Material.Neon
    Ball1.CanCollide = false
    Ball1.Locked = true
    Ball1.Size = Vector3.new(1,1,1)
    Ball1.Position = Character:WaitForChild("RightHand").Position + Vector3.new(0,.5,0)
    Spikey1.BrickColor = BrickColor.new("Royal purple")
    Spikey1.Anchored = true
    Spikey1.CanCollide = false
    Spikey1.Parent = player.Character
    Spikey1.Position = Ball1.Position
    Spikey1.Transparency = .75
    for i = 1,20 do
        Ball1.Size = Ball1.Size + Vector3.new(.05,.05,.05)
        Spikey1.Orientation = Spikey1.Orientation + Vector3.new(1,1,1)
        wait()
    end
    local BoomBoom = Ball1:Clone()
    local BV = Instance.new("BodyVelocity", BoomBoom)
    BV.Velocity = Mouse.Hit.LookVector * 100
    Ball1:Destroy()
end)
0
Because the player's mouse doesnt replicate to the server theking48989987 2147 — 4y

1 answer

Log in to vote
1
Answered by
oreoollie 649 Moderation Voter
4 years ago
Edited 4 years ago

You cannot access a player's mouse object from the server side. You're either going to need to localize the entire script or pass Mouse.Hit to the server in the "DeathBomb" RemoteEvent.

Note: A Mouse object cannot exist on the server, so passing it won't work.

If my answer solved your problem please remember to accept it.

Ad

Answer this question