This code is supposed to have a player teleport wherever their mouse is at when they press "e" and also for the player to be able to teleport even after they die but when I run it, I get an error in the output saying, "Attempt to index nil with Character" on the first line in this block of code. How do I fix this?
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(plr)
plr = game.Players.LocalPlayer
humanoid = plr.Character.HumanoidRootPart
mouse = plr:GetMouse()
mouse.KeyDown:Connect(function(key)
if key == "e" then
if mouse.Target then
humanoid.CFrame = CFrame.new(mouse.Hit.x,mouse.Hit.y + 5,mouse.Hit.z)
plr:WaitForChild("Humanoid").Died:Connect(function()
player.CharacterAdded:Wait()
mouse.KeyDown:Connect(function(key)
if key == "e" then
if mouse.Target then
humanoid.CFrame = CFrame.new(mouse.Hit.x,mouse.Hit.y + 5,mouse.Hit.z)
end
end
end)
end)
end
end
end)
end)
end)

1 comment
server doesnt have a local player. mouse cannot be obtained through the character. just create your mouse code everytime the player spawns?? :thonk: