I have TP Gui (Not made by me, made by @Jackscarlett) I am trying to make it so the player has to stand still and wait 3 seconds to be teleported to the spawn but my script didn’t work as intended.
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...
local timeCheck = Time.Value and Time.Value >= 1
local Character = player.Character or player.CharacterAdded:Wait()
player.Character wait(3)
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)
@LoafingHour,The video is an example of what am trying to get my script to do. The “script example” is my script which should be like the video but mine doesn’t 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.
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)
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)
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 @JackscarIitt that starts the event.
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
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?
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
Hey @EmbatTheHybrid, your script didn’t wrok for me.
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)
@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.