【问题标题】:Roblox: How to kill player if they don't complete a task correctly?Roblox:如果玩家没有正确完成任务,如何杀死他们?
【发布时间】:2021-04-28 18:24:48
【问题描述】:

我正在使用预制密码门,玩家必须输入正确的密码才能通过。如果本地玩家猜错密码,我希望本地玩家必须通过最后一道门杀死他们。门是2323密码门。它已经附带了一个脚本。我尝试编辑错误密码的代码:

Input = ""
local player = game.Players.LocalPlayer
local character = player.Character
character.health = 0
print("Wrong Code")

但是,我得到一个零值“字符”。 知道我做错了什么吗?谢谢。

【问题讨论】:

  • 这段代码是在 Script 还是 LocalScript 中?
  • 它似乎只是一个基于其图标的脚本。

标签: roblox


【解决方案1】:

您无法从服务器脚本访问 localplayer。以下是您可以选择的方法:

  1. 制作服务器脚本
  2. 制作远程事件
  3. 使用密码作为参数触发远程事件
  4. 把它放在你的服务器脚本中:
local remoteevent = -- reference remote event path here
local correctpass = 2323

remoteevent.OnServerEvent:Connect(function(p, pass)
    -- p is player and pass is the password the user entered
    if tonumber(pass) == correctpass then
        -- User entered correct pass so open the door
    else
        p.Character.Humanoid.Health = 0
    end
end)

最后,像这样从本地脚本触发远程事件:

local remoteevent = -- reference remote event path here
local userinput = -- get the password the user entered here
remoteevent:FireServer(userinput)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-25
    • 2019-06-17
    • 2022-06-21
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 2019-05-19
    相关资源
    最近更新 更多