角色死亡后激活重生(lua 脚本 roblox 引擎)
Activate respawn after character death (lua scripting roblox engine)
我应该如何使这段代码起作用,角色死亡后,按下按钮时激活重生功能。此时按钮起作用了,但它没有考虑角色是否死亡,我想设置只有在角色死亡时才能操作按钮的条件。最终,我可以 post 一条错误消息或其他信息,让这个人知道为什么按钮不起作用。
model = game.Workspace.MyModelName -- Replace with your model name
messageText = "Regenerating MyModelName..."
message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true
function regenerate()
message.Parent = game.Workspace
model:remove()
wait(4) -- display regen message for 4 seconds
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
message.Parent = nil
enabled = false
wait(30)
enabled = true
end
function onHit(hit)
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
regenerate()
end
end
script.Parent.Touched:connect(onHit)
script.Parent.ClickDetector.MouseClick:connect(onTouched)
将以下内容添加到您的代码中。
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
Char.Humanoid.Died:Connect(regenerate)
end)
end)
我应该如何使这段代码起作用,角色死亡后,按下按钮时激活重生功能。此时按钮起作用了,但它没有考虑角色是否死亡,我想设置只有在角色死亡时才能操作按钮的条件。最终,我可以 post 一条错误消息或其他信息,让这个人知道为什么按钮不起作用。
model = game.Workspace.MyModelName -- Replace with your model name
messageText = "Regenerating MyModelName..."
message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true
function regenerate()
message.Parent = game.Workspace
model:remove()
wait(4) -- display regen message for 4 seconds
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
message.Parent = nil
enabled = false
wait(30)
enabled = true
end
function onHit(hit)
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
regenerate()
end
end
script.Parent.Touched:connect(onHit)
script.Parent.ClickDetector.MouseClick:connect(onTouched)
将以下内容添加到您的代码中。
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
Char.Humanoid.Died:Connect(regenerate)
end)
end)