提问人:AlecSUS 提问时间:11/15/2023 最后编辑:AlecSUS 更新时间:11/17/2023 访问量:33
该值不会更改
The value doesn't change
问:
我正在制作一款剑术游戏,当你杀死一个玩家时,你会得到钱。你得到的钱是他们的等级乘以 4。我做了这个脚本:
local Players = game:GetService("Players")
function PlayerAdded(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local PStats = Instance.new("Folder", player)
PStats.Name = "PlayerStats"
local level = Instance.new("NumberValue", leaderstats)
level.Name = "Level"
level.Value = 1
local reward = Instance.new("NumberValue", PStats)
reward.Name = "Reward"
reward.Value = level.Value * 4
end
Players.PlayerAdded:Connect(PlayerAdded)
和值转换器脚本
local Players = game:GetService("Players")
local character = script.Parent
local player = Players:GetPlayerFromCharacter(character)
local humanoid = character:FindFirstChild("Humanoid")
local Level = player.leaderstats.Level
local Reward = player.PlayerStats.Reward
function UpdateReward()
if player.leaderstats.Level.Changed then
local newReward = Level.Value * 4
Reward.Value = newReward
print("1")
end
wait(1)
UpdateReward()
end
UpdateReward()
出于某种原因,当级别发生变化时,奖励值不会发生变化。我需要这方面的帮助。
我原以为奖励价值会发生变化
答:
0赞
Buzzyy
11/15/2023
#1
你不能从变量中获取值,所以你必须做 leaderstats。每次 Level.Value。
评论
0赞
AlecSUS
11/15/2023
我重新制作了该函数,但它仍然不起作用:Reward.Value = Level.Value * 4 player.leaderstats.Level.Value.Changed:Connect(function() humanoid。Reward.Value = Level.Value * 4 print(Reward.Value) 结束)
0赞
Buzzyy
11/15/2023
@AlecSUS 值是否存储在人形机器人中?
0赞
AlecSUS
11/15/2023
是的,它存储在那里
0赞
Buzzyy
11/15/2023
@AlecSUS 你真的应该将值存储在播放器的文件夹中,否则所有值在死亡时都会被重置......
0赞
AlecSUS
11/16/2023
我会努力...
评论