我不知道如何改变 Roblox 中玩家的生命值。
我试过这个:
local Object = game.Workspace.Baseplate
Object.Touched:Connect(function()
game.StarterPlayer.HealthDisplayDistance = 50
end)
local Killbrick = game.Workspace.Part
我认为第三行改变了玩家的健康状况,但它没有做任何事情。
您的问题是 Health 属性不在 Player 上,而是位于其 Character 模型的 Humanoid 上。
-- set health to 50 when touching the baseplate
local bp = game.Workspace.Baseplate
bp.Touched:Connect(function(otherPart)
-- double check that the other part is a character model
local player = game.Players:GetPlayerFromCharacter(otherPart)
if player then
-- set the player's health
player.Character.Humanoid.Health = 50
end
end)
-- make a kill brick
local Killbrick = game.Workspace.Part
bp.Touched:Connect(function(otherPart)
-- double check that the other part is a character model
local player = game.Players:GetPlayerFromCharacter(otherPart)
if player then
-- kill the player
player.Character.Humanoid.Health = 0
end
end)