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

The gui wont appear the second time. Can anyone help me?

Asked by 3 years ago
Edited 3 years ago

Hi i need some help. I posted this yesterday on discord but no one could work it out so i am hoping someone here can. I have two scripts and one teleports you into somewhere and opens a gui to leave there, and the second one when you click the gui, it teleports you out of the place and hides the gui. It works the first time but when you enter, leave and enter again, the gui doesnt appear. Here is the first script, this one teleports you in and opens the gui, It is a normal script:

local tp1 = script.Parent
local tp2 = script.Parent.Parent.Telepart
local db = true

tp1.Touched:Connect(function(hit)
    local player = hit.Parent.name
    local gui = game.Players:WaitForChild(player).PlayerGui.LeaveTp 
    if hit.Parent:FindFirstChild("Humanoid")then
        if db == true then
            db = false
            hit.Parent.HumanoidRootPart.CFrame = tp2.CFrame
            wait(0.2)
            gui.LeaveButton.Visible = true
            db = true
        end
    end
end)

and here is the second script, it teleports you out and makes the gui disappear, It is a local script:

local plr = script.Parent.Parent.Parent.Parent
local char = plr.Character

script.Parent.MouseButton1Click:Connect(function()
   char.HumanoidRootPart.CFrame = game.Workspace.LeaveTp.CFrame
   script.Parent.Visible = false
end)

If you need any other information, please ask! I think i might just be able to make the gui appear from a remote event but i need your help.

0
I'm happy to help you but this is hard to follow. Can you format this so the script shows up in lua format? Just press the lua code block above the editor! legoguy939 418 — 3y
0
ok adieking1 69 — 3y
0
There, i have updated it adieking1 69 — 3y
0
great. could you chat with me in SH chat or discord? I need to discuss the script. Its much easier to debug it that way. legoguy939 418 — 3y
0
ok discord would be fine adieking1 69 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

okay I have made some changed. let me know how this goes.

local tp1 = script.Parent
local tp2 = script.Parent.Parent.Telepart
local db = true

tp1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- you can use this for the player
        local gui = player.PlayerGui.LeaveTp 

         if db == true then
            db = false
            hit.Parent:MoveTo(tp2.Position) -- use MoveTo() for teleportation -- at least thats my preference 
            wait(0.2)
            print(player)
            print(gui)


            if player.PlayerGui.LeaveTp.LeaveButton.Visible == true then -- this was the fix. it thinks it is true when it is not so if it thinks its true just set it to false. 
                player.PlayerGui.LeaveTp.LeaveButton.Visible = false
            end



            player.PlayerGui.LeaveTp.LeaveButton.Visible = true
             db = true
        end
    end
end)

local script:

local plr = script.Parent.Parent.Parent.Parent
local char = plr.Character

script.Parent.Activated:Connect(function() -- i think activated is much better than button1click. either one is functional and fine though. I think activated might work with userinputservice. 
   char:MoveTo(game.Workspace.LeaveTp.Position)  -- i changed this to moveto again.
   script.Parent.Visible = false
end)

EDIT: after trying to fix this bug, I found a fix. But its a dumb fix. If anyone wants to look into this and repeat the same script from the original post and same simple 3 brick setup with 1 texbutton, do so. I'd love ot know why this happens.

Ad

Answer this question