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

My game teleporter crashes the Roblox client, Help?

Asked by 4 years ago
Edited 4 years ago

I need help with my teleporter. Basically it was made so if a brick is touched a Popup GUI will appear and the player will switch games, but for some reason it crashes the client instead. Here the code

Teleporter

function onTouched(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   if player then
        game:GetService("TeleportService"):Teleport(5653600014,player) 
  end
end


script.Parent.Touched:connect(onTouched)

GUI

Sound = script.Parent.Scream
Popup = script.Parent.Popup
Ready = true
function onTouch(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil and Ready == true then
Ready = false
local plyr = game.Players:FindFirstChild(h.Parent.Name)
local c = Popup:clone()
c.Parent = plyr.PlayerGui
script.Parent.Scream:play()
wait(222)
c:remove()
wait(1)
Ready = true
end
end

script.Parent.Touched:connect(onTouch)

I tried to combine them but still crashes the client. Here the link: https://www.roblox.com/games/5664353175/Teleporter-test

Combined script

function onTouched(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   if player then
        game:GetService("TeleportService"):Teleport(5653600014,player)  --replace the numbers with your place id
  end
end


script.Parent.Touched:connect(onTouched)

Sound = script.Parent.Scream2
Popup = script.Parent.Popup
Ready = true
function onTouch(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h ~= nil and Ready == true then
        Ready = false
        local plyr = game.Players:FindFirstChild(h.Parent.Name)
        local c = Popup:clone()
        c.Parent = plyr.PlayerGui
        script.Parent.Scream2:play()
        wait(222)
        c:remove()
        wait(1)
        Ready = true
    end
end

script.Parent.Touched:connect(onTouch)

0
Shoot, I should've know from Scream:Play() that it wasn't going to be pleasant. Got me good lol. Sound was up and everything. However, can you please put the full "combined" script so it's easier to diagnose what the problem is? Loughdough 291 — 4y
1
Sure thing! I added it to the question. iiXisumo 3 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

I'm not sure the exact cause of it crashing the client, but I went ahead and cleaned it up and it seems to be working fine. I think it had something to do with either there being 2 touched events or the wait(222) paired with the deprecated remove(). Anyways, here's the script:

local sound = script.Parent:WaitForChild("Scream2");
local popup = script.Parent:WaitForChild("Popup");

local debounce = false;

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent);
    local h = hit.Parent:FindFirstChild("Humanoid");

    if player and h and not debounce then
        debounce = true;

        local c = popup:Clone();
        c.Parent = player.PlayerGui;

        sound:Play();

        game:GetService("TeleportService"):Teleport(5626259107, player);

        --[[ There's no reason to wait() to remove the GUI since the player is being
             redirected to the other game anyways. ]]--

        wait(200); --// However many seconds you want to wait until a player can touch the part again.

        debounce = false;
    end
end)
0
Thank you, this fixed the Client crash issue. Thank you!!!! iiXisumo 3 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I would use a event in my way. If this script isn't what you want then R.I.P.

Script:

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        game.ReplicatedStorage.RemoteEvent:FireClient(plr)
    end
end)

LocalScript:

game.ReplicatedStorage.RemoteEvent.OnServerClient:Connect(function()
    local TS = game:GetService("TeleportService")
    local plr = game.Players.LocalPlayer
    local ID = 5653600014
    TS:Teleport(ID, plr)
end)

Not the best here at scripting, but hope this is what you're looking for by the way nice game.

Answer this question