Attempt to index nil error

For some reason, this script doesn’t work, I’ve tried looking everywhere for the solution and it really doesn’t make any sense.

Script to fire remote event

local location = mouse.Target.Location.Value

Script to teleport player when the remote event is fired

game.ReplicatedStorage.RemoteEvents.Teleport.OnServerEvent:Connect(function(player, mouseTarget, location)
	local humanoidrootpart = player.Character:WaitForChild("HumanoidRootPart")
	humanoidrootpart.CFrame = location.CFrame

The location variable is an ObjectValue set to a part, which otherwise works if you reference it on its own, like game.Workspace.Part.CFrame, but for some reason doesn’t work when you reference it like this.

I’ve also tried a string value and searching for that value, but that also causes issues.

Do you get any errors in the output?

This is because you have the mouseTarget variable in front of the location variable. You are only passing one argument over the remote meaning that the mouseTarget variable is receiving the data you want and the location variable isn’t receiving anything because nothing was passed.

Your scripts should look like this:

local location = mouse.Target.Location.Value
game.ReplicatedStorage.RemoteEvents.Teleport.OnServerEvent:Connect(function(player, location)
	local character = player.Character

	if character then

First off, capitalize the “HumanoidRootPart” like that as a variable. Second, you should pass the player object inside the FireServer function. And third, use “FindFirstChild” instead of “WaitForChild”, because WaitForChild could result in an infinite error.

People can name their variables how they want. After all, we are able to understand and read their code.

Also, why do they have to pass the player object? It’s automatically given in the receiving function.

Yes, but it doesn’t take much to capitalize it. And I have gotten errors before because I don’t pass the Player object in the initial FireServer, FireClient, etc…

I believe the first one is a LocalScript, try this:

local Player = game.Players.LocalPlayer
local Location = mouse.Target.Location.Value
mouse.Target.Clickable.RemoteEvent.Value:FireServer(Player, Location)

Then the ServerScript:

game.ReplicatedStorage.RemoteEvents.Teleport.OnServerEvent:Connect(function(Player, Location, mouseTarget)
	local HumanoidRootPart = Player.Charactder:FindFirstChild("HumanoidRootPart")
	HumanoidRootPart.CFrame = Location.CFrame

That might work? I added some of my own tweaks to it, as well as some other peoples.

You need the player object for FireClient, not FireServer

I will concede that it’s standard to capitalize variables.

However, you only have to pass the player argument when firing from the server.

That or camel-case, I personally stick with camel-case.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()

	local target = mouse.Target
	local targetLoc = target:FindFirstChild("Location")
	if targetLoc then
		mouse.Target.Clickable.RemoteEvent.Value:FireServer(target, targetLoc.Value)
game.ReplicatedStorage.RemoteEvents.Teleport.OnServerEvent:Connect(function(player, mouseTarget, location)
	local character = player.Character
	local hmr = character:WaitForChild("HumanoidRootPart")
	hmr.CFrame = location.CFrame

Is “Mouse.Target.Location” an ObjectValue instance?

When doing RemoteEvent:FireServer or RemoteFunction:InvokeServer from the client, you do not need to pass the localplayer as the first argument. Roblox already does that, just make sure your server script is set up correctly.

Note: Relying on the client to tell the server which client (itself) fired the event allows exploiters to masquerade as other players. It’s almost like seeing someone you recognise edit: recognize (as good or bad) but ignoring that fact and asking for their ID card instead which adds unnecessary vulnerability and complication.