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

What to do if some lines of code needs to be in a different script?

Hey guys,

I was just working on a boss battle that teleports you to another game when you touch a secret door. But the problem is, the touched event needs to be in a serverscript and the teleportservice needs to be in a localscript. What do I do?

Here is my code:

local teleportservice = game:GetService("TeleportService")
script.Parent.Touched:Connect(function()
	teleportservice:Teleport(5190764174)
end)

Thanks.

1 comment

1 answer

✓ Accepted answer
local teleportservice = game:GetService("TeleportService")
script.Parent.Touched:Connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then
        local plr = game.Players:FindFirstChild(hit.Parent.Name)
        teleportservice:Teleport(plr,5190764174)
    end
end)

Lol.

1 comment

0

You could you a remote event but this is a much simpler and easier way.

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