How can I make my TP Gui work?

Hey, @EmbatTheHybrid, If I do “wait (3)” the script would make the character wait 3 seconds. I need the player to stand still for 3 seconds without moving to be teleported. If the player does move the player will not get teleported.

(Am new to scripting)…

I’m surprised that doesn’t error, unique approach :thinking:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeCheckAndTeleport = ReplicatedStorage.TimeCheckRemoteEvent -- References a RemoteEvent called "TimeCheckRemoteEvent" in the ReplicatedStorage

timeCheckAndTeleport.OnServerEvent:Connect(function(player) -- Function is called when RemoteEvent is activated on the server
	local leaderstats = player:FindFirstChild("leaderstats")
	local Time = leaderstats:FindFirstChild("Time Alive")

	if leaderstats and Time then -- If player has leaderstats folder and Time leaderstat, then...
        print("Found stuff")
		local timeCheck = Time.Value and Time.Value >= 1
		local Character = player.Character or player.CharacterAdded:Wait()

        Character wait(3)

		if timeCheck and Character and Character.PrimaryPart then -- If they have 500+ time and their Character & its PrimaryPart exists, then...
            print("Teleporting")

			local newCFrame = CFrame.new(0.022, 4.638, -0.235) -- Defines new CFrame value

			Character:SetPrimaryPartCFrame(newCFrame) -- Teleports the player to the newCFrame value
		end
	end
end)

Try this and see what outputs?

Hey @Jackscarlett, I just tried your script and got this error.
image

Maybe try something like this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local timeCheckAndTeleport = ReplicatedStorage.TimeCheckRemoteEvent -- References a RemoteEvent called "TimeCheckRemoteEvent" in the ReplicatedStorage

timeCheckAndTeleport.OnServerEvent:Connect(function(player) -- Function is called when RemoteEvent is activated on the server
	local leaderstats = player:FindFirstChild("leaderstats")
	local Time = leaderstats:FindFirstChild("Time Alive")

	if leaderstats and Time then -- If player has leaderstats folder and Time leaderstat, then...
		local timeCheck = Time.Value and Time.Value >= 1
		local Character = player.Character or player.CharacterAdded:Wait()
		local Humanoid = Character:WaitForChild("Humanoid")
		
		local currentTime = 0
		local hasMoved = false
		
		repeat
			currentTime += wait(0.1)
			if Humanoid.MoveDirection ~= Vector3.new() then 
				hasMoved = true
				break
			end
		until currentTime >= 3 or hasMoved
		
		if hasMoved then 
			return 
		end

		if timeCheck and Character and Character.PrimaryPart then -- If they have 500+ time and their Character & its PrimaryPart exists, then...
			local newCFrame = CFrame.new(0.022, 4.638, -0.235) -- Defines new CFrame value

			Character:SetPrimaryPartCFrame(newCFrame) -- Teleports the player to the newCFrame value
		end
	end
end)

Not sure if there’s a better way to do this

1 Like

Hey @EmbatTheHybrid, your script worked! Are you able to make it so the label counts down from 3 to 1 though? I have a different script created by @Jackscarlett that starts the event.
image
I wrote your code in the “TP script”.

Maybe wait(1) instead of wait(0.1) would be what you need or is this completely different?

Hey @EmbatTheHybrid, No the script works perfectly fine, but if possible, how would I be able to make the Teleport GUI have a countdown from 3 to 1 like the video does?

(Sorry for the late response, apparently the forum went into maintenance.)

Oh I see, What you could do is just reference the PlayerGUi from the server and make it count down depending on the state of CurrentTime. Something like this maybe?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local timeCheckAndTeleport = ReplicatedStorage.TimeCheckRemoteEvent -- References a RemoteEvent called "TimeCheckRemoteEvent" in the ReplicatedStorage

timeCheckAndTeleport.OnServerEvent:Connect(function(player) -- Function is called when RemoteEvent is activated on the server
	local leaderstats = player:FindFirstChild("leaderstats")
	local Time = leaderstats:FindFirstChild("Time Alive")

	if leaderstats and Time then -- If player has leaderstats folder and Time leaderstat, then...
		local timeCheck = Time.Value and Time.Value >= 1
		local Character = player.Character or player.CharacterAdded:Wait()
		local Humanoid = Character:WaitForChild("Humanoid")
		
		local playerGui = player:WaitForChild("PlayerGui")
		local label = playerGui.LocationOfLabelHere
		local currentTime = 3
		local hasMoved = false
		
		label.Text = currentTime
		repeat
			currentTime -= wait(0.1)
			if Humanoid.MoveDirection ~= Vector3.new() then 
				hasMoved = true
				break
			end
			label.Text = math.ceil(currentTime)
		until currentTime <= 0 or hasMoved
		
		if hasMoved then 
			return 
		end

		if timeCheck and Character and Character.PrimaryPart then -- If they have 500+ time and their Character & its PrimaryPart exists, then...
			local newCFrame = CFrame.new(0.022, 4.638, -0.235) -- Defines new CFrame value

			Character:SetPrimaryPartCFrame(newCFrame) -- Teleports the player to the newCFrame value
		end
	end
end)

Where LocationOfLabelHere is the location of the thing you want it to display the time of

1 Like

Then try Tick(), it’s similar to wait(), but the difference is, it doesn’t stay on that line while it’s waiting, it will just continue with the program.

Hey @EmbatTheHybrid, Your script worked! I feel bad for asking for more but are you able to make it so the UI is not visible to anyone with under 500 time? :thinking:

I think what you can do is in a localscript in the Button, you can have a Changed event set up on the Time Played value so that once it is over 500, it is ivisible.

Example:

local button = script.Parent

local player = game:GetService("Players").LocalPlayer
local timePlayed = player:WaitForChild("Time Played")

button.Visible = false

timePlayed.Changed:Connect(function(newval)
    button.Visible = newval >= 500
end)

What button.Visible = newval >= 500 does is basically just make the button visible depending on the result of the condition. If it returned true then Visible is true, and vice versa

1 Like

Hey @EmbatTheHybrid, your script didn’t wrok for me. :cry:
Is this what you meant?


local player = game:GetService("Players").LocalPlayer
local timePlayed = player:WaitForChidl("Time Played")

button.Visible = false

timePlayed.Changed:Connect(function(newval)
	button.Visible = newval >= 500
end)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeCheckAndTeleport = ReplicatedStorage.TimeCheckRemoteEvent -- References a RemoteEvent called "TimeCheckRemoteEvent" in the ReplicatedStorage

local button = script.Parent

button.Activated:Connect(function()
	timeCheckAndTeleport:FireServer() -- Activates RemoteEvent when the player clicks the button
end)

(This is a local script)

I wrote your code above @Jackscarlett’s code.

You have local button = script.Parent below the code that actually uses it, put it as the first line

1 Like

@EmbatTheHybrid, I tried the code again, unfortunately it didn’t work.

-- LocalScript

local button = script.Parent

local player = game:GetService("Players").LocalPlayer
local timePlayed = player:WaitForChid("Time Played")

button.Visible = false

timePlayed.Changed:Connect(function(newval)
	button.Visible = newval >= 500
end)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeCheckAndTeleport = ReplicatedStorage.TimeCheckRemoteEvent -- References a RemoteEvent called "TimeCheckRemoteEvent" in the ReplicatedStorage

local button = script.Parent

button.Activated:Connect(function()
	timeCheckAndTeleport:FireServer() -- Activates RemoteEvent when the player clicks the button
end)

I believe

was a typo so I corrected it to “WaitForChild”, I still got the same results. :sad:

Are you getting any errors? The code looks like it should work, maybe try

button.Visible = newval >= 500 and true or false

And see if that helps? Perhaps put a print statment in the changed event to see if it’s being noticed?

1 Like

@EmbatTheHybrid, after looking at the output I got this error: image

The name at the end cut off during the screenshot, (I am doing the scripts in another account that’s why my cut off user appears as “Ga”)

Dm Me In Discord Bro: The_KillerHood#6712
Hope Can I Help You :slight_smile:

WaitForChid should be WaitForChild

1 Like

Hey @EmbatTheHybrid, the script finally works as intended.
Thank you so much for your help! :partying_face:

(Thanks to @Jackscarlett for the orginal script too!) :partying_face:

2 Likes

Glad we managed to finally help you! if you have anymore issues don’t be afraid to make another post!

1 Like