Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
LazokkYT 117
3 years ago

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.

0
Remote Events. Here's the article: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events Dovydas1118 1495 — 3y

1 answer

Log in to vote
2
Answered by 3 years ago
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.

0
You could you a remote event but this is a much simpler and easier way. PrismaticFruits 842 — 3y
Ad

Answer this question