problem: when i die and then when my character is added and i press e it says
"HumanoidRootPart is not a valid member of Model “Workspace.butter5432m”
script:
--getting all these stuff
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait(1)
local debounce = false
local mouse = plr:GetMouse()
local pos = mouse.Hit.Position
pos = CFrame.new(pos.X,pos.Y,pos.Z)
local UIS = game:GetService("UserInputService")
local Frame = plr.PlayerGui.ScreenGui.Frame
--when uis begins
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if debounce then return end
debounce = true
Frame.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
local mouse = plr:GetMouse()
local pos = mouse.Hit.Position
pos = CFrame.new(pos.X,pos.Y,pos.Z)
char.HumanoidRootPart.CFrame = pos
task.wait(3)
debounce = false
Frame.BackgroundColor3 = Color3.new(0, 255, 0)
end
end)
Also, how do i add a max distance like if i press e at the edge of the map it wont teleport me but if i do it like this
In the picture above, you will see 2 rectangles and a circle
the rectangles are the baseplate and the circle is the max you can go
since its mouse .hit it will go inf distance which i dont want
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local HRP = character:WaitForChild("HumanoidRootPart")
This should work fine, just remember to change the variables in the rest of the script.
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
userInput.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.E then
character:PivotTo(mouse.Hit)
end
end)
This is a shortened version of your script which is working for me (placed inside StarterCharacterScripts).
it means that if the character doesnt exist or if the characters parent (the player) doesnt exist then it’ll wait for it to be loaded and set the character variable to the new loaded one