so i planning to make a "Rick and Morty" portal gun that allow me to create a "Teleport pad" that will make me to teleport to another game if i click the portal. so i wrote this scripts on the tool i made
portal = false function clicked() if portal == false then portal = true local wormhole = Instance.new("Part") wormhole.Anchored = true wormhole.Parent = workspace wormhole.Name = "Hole" wormhole.Size = Vector3.new(5, 5, 1) wormhole.BrickColor = BrickColor.new("Lime green") wormhole.CFrame = script.Parent.Handle.CFrame local enter = Instance.new("ClickDetector") enter.Parent = game.Workspace.Hole wait(5) game.Workspace.Hole:remove() portal = false end end script.Parent.Activated:connect(clicked) function tp(player) if portal == true then game:GetService("TeleportService"):Teleport(938093581,player) end end game.Workspace.Hole.ClickDetector.MouseClick:connect(tp)
so it create a portal but i cant teleport to the place that i want to visit. is something wrong with my script?.
portal = false function clicked() if portal == false then portal = true local wormhole = Instance.new("Part") wormhole.Anchored = true wormhole.Parent = workspace wormhole.Name = "Hole" wormhole.Size = Vector3.new(5, 5, 1) wormhole.BrickColor = BrickColor.new("Lime green") wormhole.CFrame = script.Parent.Handle.CFrame local enter = Instance.new("ClickDetector") enter.Parent = game.Workspace.Hole enter.MouseClick:connect(function(player) if portal == true then game:GetService("TeleportService"):Teleport(938093581,player) end end) wait(5) game.Workspace.Hole:destroy() end script.Parent.Activated:connect(clicked)
Now here's one thing you need to know. You cannot write a script inside of another script
It will be much better to simply create a portal and add an "on touch" teleportation script to it instead. Then place it in ReplicatedStorage and clone it with your script instead of creating a new instance. Finally, assigning the parent of the script to the workspace and positioned (and rotated) in front of you.
Now as for TeleportService, I am not familiar with that concept as it is new to me. It could work but I dont know how, I'm more familiar with moving the CFrame of the PrimaryPart of the Character to somewhere else, that kind of teleportation.
Either way, I hope this helps a bit at least