如何调整我的leaderstats脚本,以便当触摸某个部分(pointPart1)时,玩家获得积分而不是像目前那样每秒获得积分

问题描述 投票:0回答:1

https://pastebin.com/vPgjPdnK

local Players = game:GetService("Players")
local pointPart1 = game.Workspace.PointsPlaceFolder.PointPart1

local function onCharacterAdded(character, player)
    player:SetAttribute("IsAlive", true)
    
    local humanoid = character:WaitForChild("Humanoid")
    
    humanoid.Died:Connect(function()
        local points = player.leaderstats.Points
        points.Value = 0
        player:SetAttribute("IsAlive", false)
    end)
end

local function onPlayerAdded(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Value = 0
    points.Parent = leaderstats
    
    player:SetAttribute("IsAlive", false)
    
    player.CharacterAdded:Connect(function(character)
        onCharacterAdded(character, player)
    end)
end

Players.PlayerAdded:Connect(onPlayerAdded)

while true do
    task.wait(1)
    local playerList = Players:GetPlayers()
    for i = 1, #playerList do
        local player = playerList[i]
        if player:GetAttribute("IsAlive") then
            local points = player.leaderstats.Points
            points.Value += 1
        end
    end
end

我尝试添加另一个函数,基本上 onTouch 会导致 10 点增益然后中断。我有概念问题,所以它可能没有准确地执行,但没有错误/语法。

lua scripting
1个回答
0
投票

这个

local pointPart1 = game.Workspace.PointsPlaceFolder.PointPart1

blacklist = {}
blacklist.findPlayer = function(player)
    for i,v in ipairs(blacklist) do
        if v==player then
            return true
        end
    end
    return false
end

PointPart1.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild(“Humanoid”) then
    thePlayer = game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild(“Humanoid”).Parent)
    if(thePlayer and not blacklist.findPlayer(thePlayer))
        thePlayer.leaderstats.Points.Value+=1
        table.insert(blacklist,thePlayer)
   end
end)

每当该部件被触摸时,都会为玩家添加一个积分,但是如果您仍然希望玩家仍然能够从该部件中获得积分,则将玩家添加到黑名单中,这样玩家就不允许再次触摸它稍后,需要不同的解决方案

© www.soinside.com 2019 - 2024. All rights reserved.