传送到 Spawn 脚本
Teleport to Spawn script
有谁知道哪里出了问题,脚本应该是如果你的时间比你的时间多 750 倍,那么传送按钮就会变得可见并且那部分可以工作,但是当它到达你的位置时它就会停止工作单击并且开发控制台中没有错误出现。我认为正在发生的事情是事件不会在该行之后触发,因为我尝试在之后立即打印但没有打印任何内容,所以我认为事件不会以某种方式触发。当您单击按钮时,文本应先变为 3,然后变为 2,然后变为 1,然后恢复到原来的状态,然后您会被传送到出生点,如果您移动角色,它就会重置,这样文本就会恢复正常,但不会传送你,你必须再次单击它并一直保持静止才能传送你。另外,pog 是我添加到播放器中的布尔值,它的默认值为 false,当你进入时该值就在那里。
代码在文本按钮中的本地脚本中,在 startergui 中的 screengui 中:
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)
问题
您在 while 循环下连接到按钮。脚本在分配按钮单击按钮之前等待 while 循环结束,但循环永远不会结束,因此没有连接。
解决方案
只需将 .MouseButton1Click
和变量 pog
事件放在 while 循环之前即可。 (只需在 while 循环之前将第 12 行中和下面的所有内容移动)。
如果您有任何问题,请随时提问。如果这解决了您的问题,请确保将此标记为答案,以便其他人从中受益。
代码
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
此外,我强烈建议在 .MouseButton1Click
函数下使用 repeat 而不是 while 循环。
有谁知道哪里出了问题,脚本应该是如果你的时间比你的时间多 750 倍,那么传送按钮就会变得可见并且那部分可以工作,但是当它到达你的位置时它就会停止工作单击并且开发控制台中没有错误出现。我认为正在发生的事情是事件不会在该行之后触发,因为我尝试在之后立即打印但没有打印任何内容,所以我认为事件不会以某种方式触发。当您单击按钮时,文本应先变为 3,然后变为 2,然后变为 1,然后恢复到原来的状态,然后您会被传送到出生点,如果您移动角色,它就会重置,这样文本就会恢复正常,但不会传送你,你必须再次单击它并一直保持静止才能传送你。另外,pog 是我添加到播放器中的布尔值,它的默认值为 false,当你进入时该值就在那里。
代码在文本按钮中的本地脚本中,在 startergui 中的 screengui 中:
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)
问题
您在 while 循环下连接到按钮。脚本在分配按钮单击按钮之前等待 while 循环结束,但循环永远不会结束,因此没有连接。
解决方案
只需将 .MouseButton1Click
和变量 pog
事件放在 while 循环之前即可。 (只需在 while 循环之前将第 12 行中和下面的所有内容移动)。
如果您有任何问题,请随时提问。如果这解决了您的问题,请确保将此标记为答案,以便其他人从中受益。
代码
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
此外,我强烈建议在 .MouseButton1Click
函数下使用 repeat 而不是 while 循环。