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

My teleport player script isn't working?

script.Parent.Touched:Connect(function(hit)
	local spawns = script.Parent.Parent.Spawns:GetChildren()
	
	hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns))
end)

Thanks!

2 comments

0

Error: CFrame.new(math.random(1,#spawns))

0

Could you possibly mean CFrame.new(spawns[math.random(1, #spawns)].Position)?

3 answers

You will use Vector as my new script here

--//  Author: EnzoTDZ_YT

script.Parent.Touched:Connect(function(hit)
    local spawns = script.Parent.Parent.Spawns:GetChildren()
--    hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns)) --//  OLD
	hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(math.random(1,#spawns.Position))) --//  NEW
end)

10 comments

0

Still throws an error.

0

they may be a problem with your spawns

0

Math.random returns a number not an object value

0

I use MoveTo() seems to work fine for me

0

math.random() doesn't return 3 numbers

0

I don’t know how to index a object value to a string value but maybe try it now

0

It says line 3 is a bad argument (interval is empty)

0

It says line 3 is a bad argument (interval is empty)

0

It says line 3 is a bad argument (interval is empty)

0

Is the script in the brick? it is supposed be in the brick as its first child

script.Parent.Touched:Connect(function(hit)
    local spawns = script.Parent.Parent.Spawns:GetChildren()
	local ChosenSpawn = spawns[math.random(1,#spawns)]
    	local Player = hit.Parent:FindFirstChild("HumanoidRootPart")
	if Player then
		Player.CFrame = ChosenSpawn.CFrame
	end
end)

This should work

3 comments

0

It says line 3 is a bad argument (interval is empty)

0

That means that #spawns < 1.

0

I used this for the alvinblox tutorial and it worked.

script.Parent.Touched:Connect(function(hit)
    local spawns = script.Parent.Parent.Spawns:GetChildren()

    hit.Parent:FindFirstChild("HumanoidRootPart").Position = CFrame.new(math.random(1,#spawns).Position)
end)

Maybe this will work. Try it! <3

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