You need to enable JavaScript to run this app. Roblox中关联Proximity Prompt的脚本如何更新触发玩家的leaderstats
优惠活动
大模型
产品
解决方案
定价
更多

Roblox中关联Proximity Prompt的脚本如何更新触发玩家的leaderstats

实现代码与注意事项

完整修改后的触发逻辑代码

script.Parent.ProximityPrompt.Triggered:Connect(function(Player)
    if Player.Backpack:FindFirstChild("Card") or Player.Character:FindFirstChild("Card") then
        -- 等待加载leaderstats避免时序报错
        local leaderstats = Player:WaitForChild("leaderstats")
        -- 将下方的Points替换为你实际要修改的leaderstats下的数值名称
        local targetStat = leaderstats:WaitForChild("Points")
        -- 示例:数值+10,可自行修改为需要的赋值逻辑
        targetStat.Value += 10
        -- 若要设置固定值可写为 targetStat.Value = 100
    else
        print("You must be a crm for this")
    end
end)

必须满足的前置条件

  • 上述触发脚本必须为服务端脚本,放置在Workspace的触发部件下,不可放在客户端运行的容器(如StarterPlayerScripts、StarterPack)中,否则数值修改不会全局同步
  • 需要提前在服务端初始化玩家的leaderstats结构,初始化示例代码(需放在ServerScriptService的服务端脚本中):
game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player

    -- 示例创建名为Points的数值,可自行修改名称、初始值、数值类型
    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Value = 0
    points.Parent = leaderstats
end)

内容的提问来源于stack exchange,提问作者dacocoma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 09:45:03