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

Why it doesnt add points or makes part invisible?

Asked by 1 year ago

I want to make that this script adds 10 points to player after they click a part and this part goes invisible, but it doesnt work.

local Part1 = script.Parent
local CD = Part1.ClickDetector

local function addPoint(playerpoints, part)
    local pointadd = 10
    playerpoints.Value += pointadd
    part.Transparency = 1
end

local function clickedPart(ClickParent)
    local character = ClickParent.Parent
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
        local lb = player:FindFirstChild("leaderstats")
        local playerpoints = lb:FindFirstChild("Points")
        addPoint(playerpoints, Part1)
    end
end


CD.MouseClick:Connect(clickedPart)

1 answer

Log in to vote
1
Answered by
pwx 1581 Moderation Voter
1 year ago
Edited 1 year ago

A ClickDetector sends over a player parameter, I'm not sure what you mean by 'ClickParent'.

local Part1 = script.Parent
local CD = Part1:WaitForChild('ClickDetector')

local function addPoint(Points, Part)
    local pointsToAdd = 10
    Points.Value += pointsToAdd
    Part.Transparency = 1
end

local function onClicked(Player)
    local Character = Player.Character
    if Character then
        local Humanoid = Character:FindFirstChild('Humanoid')
        if Humanoid then
            local leaderstats = Player:FindFirstChild('leaderstats')
            local playerPoints = leaderstats:FindFirstChild('Points')
            if playerPoints then
                addPoint(playerPoints, Part1)
            end
        end
    end
end

CD.MouseClick:Connect(onClicked)

Ad

Answer this question