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

Teleporter script not working?

I created a local script that teleports you to a set of coordinates depending on a certain value. However, it does not work, and the output shows nothing about this script. Here it is (apologies for messiness and length)

char = game.Players.LocalPlayer.Character
planet = game.Workspace.StarshipWiz.Planet.Value
db = game.Workspace.StarshipWiz.db
function teleporter()
	if db == true then
local s = Instance.new("Sound")
s.SoundId = "http://www.roblox.com/asset?id=137064059"
s.Parent = char.Torso
local c = s:clone()
c.Parent = game.Workspace.StarshipWiz["Captain's Chair"].Controlpad
if planet == "Earth" then 
char.Torso.CFrame = Vector3.new(-1441.151, 18.113, -160.96)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else
if planet == "Chrome" then
char.Torso.CFrame = Vector3.new(2579.555, 2739.255, 826.241)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else	
if planet == "Gold" then
char.Torso.CFrame = Vector3.new(2223.555, 2739.255, 1848.24)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else
if planet == "Lavaland" then
char.Torso.CFrame = Vector3.new(5186.117, 1826.648, 2649.986)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else
if planet == "Raxava Delta" then
char.Torso.CFrame = Vector3.new(-139.283, 967.748, -1860.5)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else
if planet == "Space Station" then
char.Torso.CFrame = Vector3.new(-1412.15, 3602.906, -336.96)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else
if planet == "The Countryside" then
char.Torso.CFrame = Vector3.new(5283.634, 1828.823, 4460.387)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else
if planet == "Venice" then
char.Torso.CFrame = Vector3.new(-914.9, 913.503, -1651.5)
s:Play()
c:Play()
script.Parent.Parent.Parent.Parent:destroy()
else return end
end
end	
end
end
end
end
end
else return end
end
	

script.Parent.MouseButton1Click:connect(teleporter)

Please help?

2 comments

0

You should move s:Play() c:Play() and the script.Parent.Parent.Parent.Parent:Destroy() lines outside the if statement (since they're in every possibility except "else return", and so are guaranteed to run unless the "else" executes) so that those lines aren't repeated (making it easier to change/manage later)

0

Why df did this get so many thumbs down?

1 answer

✓ Accepted answer
  1. db is an instance not a bool value, use .Value to get it's boolean
  2. use CFrame.new() to define a new cframe
  3. put planet inside the function so everytime the function is activated, the value is updated
  4. Not sure if it would matter, but capitalize Destroy()
  5. Indented to make it less messy, get in the habit of indenting
char = game.Players.LocalPlayer.Character
db_instance = game.Workspace.StarshipWiz.db --this is an instance not a boolean
function teleporter()
	local db = db_instance.Value --find it's boolean
    if db == true then
		local planet = game.Workspace.StarshipWiz.Planet.Value
		local s = Instance.new("Sound")
		s.SoundId = "http://www.roblox.com/asset?id=137064059"
		s.Parent = char.Torso
		local c = s:clone()
		c.Parent = game.Workspace.StarshipWiz["Captain's Chair"].Controlpad
		if planet == "Earth" then 
			char.Torso.CFrame =  CFrame.new(Vector3.new(-1441.151, 18.113, -160.96))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "Chrome" then
			char.Torso.CFrame =  CFrame.new(Vector3.new(2579.555, 2739.255, 826.241))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "Gold" then
			char.Torso.CFrame =  CFrame.new(Vector3.new(2223.555, 2739.255, 1848.24))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "Lavaland" then
			char.Torso.CFrame =  CFrame.new(Vector3.new(5186.117, 1826.648, 2649.986))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "Raxava Delta" then
			char.Torso.CFrame = CFrame.new(Vector3.new(-139.283, 967.748, -1860.5))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "Space Station" then
			char.Torso.CFrame = CFrame.new(Vector3.new(-1412.15, 3602.906, -336.96))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "The Countryside" then
			char.Torso.CFrame = CFrame.new( Vector3.new(5283.634, 1828.823, 4460.387))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		elseif planet == "Venice" then
			char.Torso.CFrame = CFrame.new(Vector3.new(-914.9, 913.503, -1651.5))
			s:Play()
			c:Play()
			script.Parent.Parent.Parent.Parent:Destroy()
		else return end
	else return end
end


script.Parent.MouseButton1Click:connect(teleporter)


1 comment

0

Thanks!

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