【问题标题】:Teleport to Spawn script传送到 Spawn 脚本
【发布时间】:2021-07-03 18:41:39
【问题描述】:

有谁知道出了什么问题,脚本应该是,如果你的时间比你的时间多 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)

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    问题

    您已连接到 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 函数下使用重复而不是 while 循环。

    【讨论】:

    • 嗯,它没有工作,它也不能做任何事情,因为 while 循环在 .MouseButton1Click 事件之前关闭,它基本上会以相同的方式运行
    • @Betreyal 不,它不会,你的while循环永远不会结束,因为它没有break,所以这意味着它不会运行之后的代码。因此,只需将 while 循环之后的所有内容移到 while 循环之前,并将其放在最后。另外,我说的是顶部的 while 循环,而不是 MoustButton1Click 函数中的那个。
    • 哦,是的,它现在工作了,只是这件事有​​问题,我不得不重新排序代码,但它最终还是工作了。
    猜你喜欢
    • 2017-09-02
    • 2015-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 1970-01-01
    相关资源
    最近更新 更多