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

Brick awarding point help? [Solved]

Hey there biocommand here, I am working in some games and have the same problem with this, what I am trying to do is a brick that awards points when the player steps on it (Not player points) and it´s not working I used the one from roblox wiki and it might be outdated, heres the script:


local enabled = true
 
game.Players.PlayerAdded:connect(function(player)
	local leader, score = Instance.new('IntValue', player), Instance.new('IntValue')
	leader.Name = 'leaderstats'
	score.Name = 'Score'
	score.Parent = leader
end)
 
Workspace.Button.Touched:connect(function(hit)
	local p = game.Players:FindFirstChild(hit.Parent.Name)
	if pl and enabled == true then
		enabled = false
		p.leaderstats.Score.Value = p.leaderstats.Score.Value + 5
		wait(20)
		enabled = true
	end
end)

here´s the leaderboard if the problem is with that

game.Players.PlayerAdded:connect(function(player)
	local leader, score = Instance.new('IntValue', player), Instance.new('IntValue')
	leader.Name = 'leaderstats'
	score.Name = 'Score'
	score.Parent = leader
end)

Also I put both with scripts, not local scripts.

1 answer

There are two things wrong with your code:

local enabled = true

game.Players.PlayerAdded:connect(function(player)
    local leader, score = Instance.new('IntValue', player), Instance.new('IntValue')
    leader.Name = 'leaderstats'
    score.Name = 'Score'
    score.Parent = leader
end)

Workspace.Button.Touched:connect(function(hit)
    local p = game.Players:FindFirstChild(hit.Parent.Name) -- If there is not a player that has the name of a part's parent that touches button, then the script will error. Check if humanoid is in hit's parent.
    if pl and enabled == true then -- pl is undefined. You probably meant p.
        enabled = false
        p.leaderstats.Score.Value = p.leaderstats.Score.Value + 5
        wait(20)
        enabled = true
    end
end)

Hope I've helped!

4 comments

0

Thanks I already corrected the pl, but what do I do in the first error? I mean how do I correct that? I am new to scripting

0

Whoops, nevermind. You should be fine as long as you've fixed that error. I just saw that you were using FindFirstChild. Is the script working? Are there any errors in output? I'd be glad to help

0

its working fine :D thank you very much :D

0

Mhm - no problem!

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