Reputation: 13
Does anyone know what is wrong, the script is supposed to be if you have 750 times more time than your time multi then the teleport button becomes visible and that part works but then it stops working when it gets to where you click and no errors come up in the dev console. What I think is happening is that the event doesnt fire after that line because I tried print right after and nothing printed, so i think the event isnt firing somehow. When you click on the button the text should change to 3 then 2 then 1 then back to how it was and you get teleported to spawn and if you move your character then it resets so the text would be back to normal and it wouldn't teleport you and you would have to click it again and stay still the whole time for it to teleport you. Also the pog thing was a boolvalue I added into the player and its default value is false and the value is there when you go in.
Code is in a local script in the text button which is in a screengui that is in startergui:
player = game.Players.LocalPlayer
character = game.Workspace[player.Name]
while true do
wait(1)
if player.leaderstats.Time.Value < player.TimeMulti.Value*750 then
script.Parent.Visible = false
elseif player.leaderstats.Time.Value >= player.TimeMulti.Value*750 then
script.Parent.Visible = true
end
end
local pog = player.pog.Value
script.Parent.MouseButton1Click:Connect(function()
pog = true
while pog == true do
wait (1)
character.Humanoid.Changed:Connect(function()
if character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "Teleport to spawn"
then
script.Parent.Text = "3"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "3" then
script.Parent.Text = "2"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "2" then
script.Parent.Text = "1"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "1" then
character.Torso.CFrame = game.Workspace.Spawn.SpawnLocation.CFrame
script.Parent.Text = "Teleport to spawn"
elseif character.Humanoid.MoveDirection.Magnitude ~= 0 then
script.Parent.Text = "Teleport to spawn"
pog = false
end
end)
end
end)
Upvotes: 1
Views: 938
Reputation: 68
You have the connection to the button under the while loop. The script waits for the while loop to end before assigning the button click button but the loop never ends so there is no connection.
Just put the .MouseButton1Click
and the variable pog
event before the while loop. (just move everything in and under line 12 before the while loop).
If you have any questions make feel free to ask. If this solved your issue please make sure to mark this as the answer so other people benefit from it.
player = game.Players.LocalPlayer
character = game.Workspace[player.Name]
local pog = player.pog.Value
script.Parent.MouseButton1Click:Connect(function()
pog = true
while pog == true do
wait (1)
character.Humanoid.Changed:Connect(function()
if character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "Teleport to spawn"
then
script.Parent.Text = "3"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "3" then
script.Parent.Text = "2"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "2" then
script.Parent.Text = "1"
elseif character.Humanoid.MoveDirection.Magnitude == 0 and script.Parent.Text == "1" then
character.Torso.CFrame = game.Workspace.Spawn.SpawnLocation.CFrame
script.Parent.Text = "Teleport to spawn"
elseif character.Humanoid.MoveDirection.Magnitude ~= 0 then
script.Parent.Text = "Teleport to spawn"
pog = false
end
end)
end
end)
while true do
wait(1)
if player.leaderstats.Time.Value < player.TimeMulti.Value*750 then
script.Parent.Visible = false
elseif player.leaderstats.Time.Value >= player.TimeMulti.Value*750 then
script.Parent.Visible = true
end
end
Also, I highly recommend using a repeat instead of a while loop under the .MouseButton1Click
function.
Upvotes: 0