Here's the deal, I'm incorporating a teleportation system with a tool on Roblox Studio. However, this error has got me stumped. I will provide the code and other useful sources below and describe the issue after.
local tool = script.Parent.Parent
local debounce = false
local afterTeleport = false
local plrName = game.Players.LocalPlayer.Name
local char = workspace:FindFirstChild(plrName)
tool.Activated:connect(function(m)
if debounce == false then
local hum = game.Players.LocalPlayer.Character.Humanoid
local anim_feet = hum:LoadAnimation(script.Parent.Animation)
local current = anim_feet
local bodyVelocity = tool.Handle.LocalScript.BodyVelocity:Clone()
debounce = true
current:Play()
wait(1.1)
local gui = script.Parent.TransitionGui:Clone()
-- Properties for UI
gui.Parent = game.Players.LocalPlayer.PlayerGui
-- Transition
gui.Frame.BackgroundTransparency = 1
wait(0.02)
gui.Frame.BackgroundTransparency = 0.8
wait(0.02)
gui.Frame.BackgroundTransparency = 0.6
wait(0.02)
gui.Frame.BackgroundTransparency = 0.4
wait(0.02)
gui.Frame.BackgroundTransparency = 0.2
wait(0.02)
gui.Frame.BackgroundTransparency = 0
-- Teleport Player Into Sky Above Them
hum.Parent.HumanoidRootPart.CFrame =
CFrame.new(Vector3.new(hum.Parent.HumanoidRootPart.CFrame.X, hum.Parent.HumanoidRootPart.CFrame.Y + 700, hum.Parent.HumanoidRootPart.CFrame.Z))
bodyVelocity.Parent = hum.Parent.HumanoidRootPart
afterTeleport = true
wait(0.02)
gui.Frame.BackgroundTransparency = 0.2
wait(0.02)
gui.Frame.BackgroundTransparency = 0.4
wait(0.02)
gui.Frame.BackgroundTransparency = 0.6
wait(0.02)
gui.Frame.BackgroundTransparency = 0.8
wait(0.02)
gui.Frame.BackgroundTransparency = 1
wait(0.02)
end
end)
char.Touched:Connect(function(interact)
local hum = game.Players.LocalPlayer.Character.Humanoid
if afterTeleport == true then
if interact:IsA("Terrain") then
if hum.Parent.HumanoidRootPart:FindFirstChild("BodyVelocity") then
hum.Parent.HumanoidRootPart.BodyVelocity:Destroy()
end
elseif interact:IsA("Part") then
if hum.Parent.HumanoidRootPart:FindFirstChild("BodyVelocity") then
hum.Parent.HumanoidRootPart.BodyVelocity:Destroy()
end
elseif interact:IsA("MeshPart") then
if hum.Parent.HumanoidRootPart:FindFirstChild("BodyVelocity") then
hum.Parent.HumanoidRootPart.BodyVelocity:Destroy()
end
end
end
end)
To me, this seems correct. But the issue is whenever I play-test the code, the output displays an error that I don't understand. The output error is:
16:35:59.453 Players.BigBetterBuilder.Backpack.Sky Port.Handle.LocalScript:58: attempt to index nil with 'Touched'?
My goal for this tool is that when it is activated, it will teleport you into the sky 700 studs above the players' current position. It will add a BodyVelocity to the player's HumanoidRootPart causing the player to slow down the decent speed, and when the player touched the ground. It should remove the BodyVelocity allowing the player to roam around without having weird gravity.
But the function that's supposed to detect when a player touches the ground isn't working. And I, unfortunately, can't seem to solve the problem.
question from:
https://stackoverflow.com/questions/65648117/attempt-to-index-nil-with-touched 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…