Attempt to index nil with position error

Hello I am trying to make a glory kill script but as of right now I just have a script that fires a remote event when the key F is pressed. Whenever it gets it on the server it doesn’t print and insteads error with the error being the title.

function attack(player, target)
	if (player.Character.HumanoidRootPart.Position - target.Position).Magnitude < 2 then
		if target.Name == "Humanoid" then
			print("yes")
		end
	end
end

script.Parent.RemoteEvent.OnServerEvent:Connect(attack)

Can you provide the client side? Its pretty hard to answer your question when we dont know what target is :moyai:

thats probably my issue because I dont have a target on client.

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		script.Parent.RemoteEvent:FireServer()
	end
end)

Im still learning remote events and this is my first time using them without a vial tutorial

Yeh thats your issue, you dont pass an argument for target so target is nil, and nil has no properties or attributes called Position, or anything for that matter

How would I add target onto the client then?

You could cast a ray to the mouse, get the mouse.Hit, get it with a hitbox, etc. It depends how you want to get the target

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.