Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why it doesnt add points or makes part invisible?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.