Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why wont it add points to the leader stats?

Asked by 5 years ago

this script is to pick up a coin and to add a point on the leader stats but it won't let me add the points to the leader stats.

local coin = script.Parent

function ont(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        Points.Value = Points.Value + 1
        coin:Destroy()
    end
end

game.Workspace.Part.Touched:connect(ont)

3 answers

Log in to vote
0
Answered by
G2001H 75
5 years ago
Edited 5 years ago

Use Script and put into the part u want to collect

local coin = script.Parent

function ont(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
    local Points = plr:FindFirstChild("leaderstats").Points
        Points.Value = Points.Value + 1
        coin:Destroy()
        end
    end
end

coin.Touched:Connect(ont)
Ad
Log in to vote
0
Answered by 5 years ago

You never defined Points.

local coin = script.Parent

function ont(hit)
    local player = hit.Parent and game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    local ls = player and player:FindFirstChild('leaderstats')
    local points = ls and ls:FindFirstChild('Points')

    if points ~= nil then
        points.Value = points.Value + 1
        coin:Destroy()
    end
end

workspace.Part.Touched:connect(ont)
Log in to vote
0
Answered by
0_2k 496 Moderation Voter
5 years ago

Not sure if anything was defined, give this a shot? Added a debounce so there's a cooldown, feel free to remove this if you please.

local db = false
workspace.Part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = plr:FindFirstChild("leaderstats")
        if not db then
            db = true
            stats.Points.Value = Points.Value + 1
            wait(3)
            db = false
        end
    end
end)

Answer this question