What do you want to achieve? Keep it simple and clear!
To see what cause the error in the output.
What is the issue? Include screenshots / videos if possible!
So I made that when a player touch a part, they will be teleported to their last completed stage and it worked! But an error occurs and I don’t know why.
Below is the script that I use in the part.
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local RandomStats = plr.RandomStats
local Stage = RandomStats.Stage
if humanoid ~= nil then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace.Stages[Stage.Value].Position + Vector3.new(0,5,0))
end
end)
The error that occur in the output is ==> Workspace.TPparts.Part.Script:4: attempt to index nil with ‘RandomStats’
u have to check if the hitpart actually is inside a player character
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local RandomStats = plr.RandomStats
local Stage = RandomStats.Stage
if humanoid ~= nil then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace.Stages[Stage.Value].Position + Vector3.new(0,5,0))
end
end
end
end)