Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why wont the player's humanoidrootpart get teleported to the chosen part?

local function inroundtrue ()
	for _, plr in pairs(players:GetPlayers()) do
		if inround.Value == true then
			if forestmapworkspace.Value == true then
				local character = plr.Character or plr.CharacterAdded:Wait()
				local rootpart = character.HumanoidRootPart
				local tpparts = maps:WaitForChild("Forest"):WaitForChild("TPParts")
				local randomtppart = math.random(1, 12)
				if randomtppart == 1 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart1").CFrame
				elseif randomtppart == 2 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart2").CFrame
				elseif randomtppart == 3 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart3").CFrame
				elseif randomtppart == 4 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart4").CFrame
				elseif randomtppart == 5 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart5").CFrame
				elseif randomtppart == 6 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart6").CFrame
				elseif randomtppart == 7 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart7").CFrame
				elseif randomtppart == 8 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart8").CFrame
				elseif randomtppart == 9 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart9").CFrame
				elseif randomtppart == 10 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart10").CFrame
				elseif randomtppart == 11 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart11").CFrame
				elseif randomtppart == 12 then
					rootpart.CFrame = tpparts:WaitForChild("TPPart12").CFrame
				else
					print("tppart forest doesnt work")
				end
			else
				print("Inround.Value == true doesnt work")
			end

		else
			print("Inround.Changed doesnt work")
		end


	end
end

1 answer

To my knowledge, you need to use the "SetPrimaryPartCFrame" function on the character, and another issue with your code is there are a lot of if else checks, you can just do this instead of checking every possible outcome:

local function inroundtrue ()
    for _, plr in pairs(players:GetPlayers()) do
        if inround.Value == true then
            if forestmapworkspace.Value == true then
                local character = plr.Character or plr.CharacterAdded:Wait()
                local rootpart = character.HumanoidRootPart
                local tpparts = maps:WaitForChild("Forest"):WaitForChild("TPParts")
                local randomtppart = math.random(1, 12)
		character:SetPrimaryPartCFrame(tpparts:WaitForChild("TPPart"..randomtppart)) -- We are using the built in function for models
                end
            else
                print("Inround.Value == true doesnt work")
            end

        else
            print("Inround.Changed doesnt work")
        end


    end
end

I edited this to remove the if statement on randomtppart because it's not possible for it to go lower or higher than the minimum/maximum.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.