Attempt to index nil with 'p'

I made a magic skill but it doesnt work
[08:21:17.350 - ServerScriptService.HieHie.IceBird:13: attempt to index nil with ‘p’]

game.ReplicatedStorage.HieMi.IcePol.IceBird.OnServerEvent:Connect(function(player, Mouse)
	
	local Character = player.Character
	local soundik = Instance.new("Sound", Character.Torso)
	soundik.SoundId = "rbxassetid://3744391247"
	soundik.MaxDistance = 300 
	
	local icebird = game.ReplicatedStorage.HieMi.IcePol.anivia:Clone()
	icebird.CFrame = CFrame.new(Character.Head.CFrame.p , Mouse.p) + CFrame.new(Character.Head.CFrame.p , Mouse.p).lookVector * 3 
	
	local bodyVelo = Instance.new("BodyVelocity")
	bodyVelo.Velocity = icebird.CFrane.lookVector * 125
	bodyVelo.MaxForce = Vector3.new(1e6, 1e6, 1e6)
	bodyVelo.Parent = icebird
	
	icebird.Parent = workspace
	
	--soundik:Play()
	
end)
2 Likes

I am pretty sure you can’t fire the mouse to the server, maybe fire the mouse.hit.p to the server.
When I fired the mouse to the server in the past, it was nil.

Mouse.p is not a thing. Mouse.Hit.p is however, and would give you the position that the hits in 3d space.

1 Like

Could you show us what you are firing inside of the remote event, I’m assuming you are sending the parameter of Mouse.Hit to be able to call Mouse.p? If you aren’t firing that then that should be your problem, to be able to access the position from the mouse, you need to call Mouse.Hit.

Lua example from documentation:

local position = mouse.Hit.p

Mouse.Hit documentation

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.X and cd == false then
cd = true
game.ReplicatedStorage.HieMi.IcePol.IceBird:FireServer(Mouse.Hit)
wait(5)
cd = false
end
end)

[ Hit is not a valid member of CFrame]

I’m assuming that
Mouse = game.Players.LocalPlayer:GetMouse()
right?

Also, in that first bit you posted, “bodyVelo.Velocity = icebird.CFrane.lookVector * 125”
is supposed to be “bodyVelo.Velocity = icebird.CFrame.lookVector * 125”

Yes, i change CFrane but idk how to fix

“[ Hit is not a valid member of CFrame]”

Did you fire the mouse.Hit to the server? The player’s mouse and not the Hit.P of the mouse?
I think you should fire the Hit.P of the mouse and not the mouse.Hit, but I am not sure.
like this:

game.ReplicatedStorage.HieMi.IcePol.IceBird:FireServer(Mouse.Hit.P)

And remove the .p in the server script if you do that.

This is local script (StarterPlayerScripts)

local uis = game:GetService(“UserInputService”)
local cd = false
local Mouse = game.Players.LocalPlayer:GetMouse()

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Z and cd == false then
cd = true
game.ReplicatedStorage.HieMi.IcePol.IceFloorka:FireServer()
wait(5)
cd = false
end
end)

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.X and cd == false then
cd = true
game.ReplicatedStorage.HieMi.IcePol.IceBird:FireServer(Mouse.Hit)
wait(5)
cd = false
end
end)

Try to fire the Mouse.Hit.P instead of Mouse.Hit, and in the server remove the .p after the mouse. That way you fire a position.
Like this I think:

This is local script (StarterPlayerScripts)

local uis = game:GetService(“UserInputService”)
local cd = false
local Mouse = game.Players.LocalPlayer:GetMouse()

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Z and cd == false then
cd = true
game.ReplicatedStorage.HieMi.IcePol.IceFloorka:FireServer()
wait(5)
cd = false
end
end)

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.X and cd == false then
cd = true
game.ReplicatedStorage.HieMi.IcePol.IceBird:FireServer(Mouse.Hit.p)
wait(5)
cd = false
end
end)

and in the server, the line will look like this:

	icebird.CFrame = CFrame.new(Character.Head.CFrame.p , Mouse) + CFrame.new(Character.Head.CFrame.p , Mouse).lookVector * 3 

Because you fire the position and not the mouse.Hit

1 Like

Thanks for help, this method works!

1 Like

Great! Please mark my answer as a solution is if it works fine :grinning:

I’d also just like to comment that it’s bad practice to use the same connection twice, along with letting cooldowns be client sided as that’s easily exploitable.

-- Local Script
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input, Process)
    if not Process and Input.UserInputType == Enum.UserInputType.Keyboard then
        if Input.KeyCode == Enum.KeyCode.Z then
            game.ReplicatedStorage.HieMi.IcePol.IceFloorka:FireServer()
        elseif Input.KeyCode == Enum.KeyCode.X then
            game.ReplicatedStorage.HieMii.IcePol.IceBird:FireServer(Mouse.Hit.p)
        end
    end
end)
--Server
local Debounce = {}

game.ReplicatedStorage.HieMii.IcePol.IceBird.OnServerEvent:Connect(function(Player, Position)
    if Player and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") and not Debounce[Player] then
        Debounce[Player] = true
        local Character = player.Character
	    local soundik = Instance.new("Sound", Character.Torso)
	    soundik.SoundId = "rbxassetid://3744391247"
 	    soundik.MaxDistance = 300 
	
	    local icebird = game.ReplicatedStorage.HieMi.IcePol.anivia:Clone()
	    icebird.CFrame = CFrame.new(Character.Head.CFrame.p , Position) + CFrame.new(Character.Head.CFrame.p , Position).lookVector * 3 
	
	    local bodyVelo = Instance.new("BodyVelocity")
	    bodyVelo.Velocity = icebird.CFrane.lookVector * 125
	    bodyVelo.MaxForce = Vector3.new(1e6, 1e6, 1e6)
	    bodyVelo.Parent = icebird
	
	    icebird.Parent = workspace
        delay(5, function()
            if Player then Debounce[Player] = false end
        end)
    end
end)
1 Like

Thanks for tip, I will consider!

1 Like