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.

01local coin = script.Parent
02 
03function ont(hit)
04    if hit.Parent:FindFirstChild("Humanoid") then
05        Points.Value = Points.Value + 1
06        coin:Destroy()
07    end
08end
09 
10game.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

01local coin = script.Parent
02 
03function ont(hit)
04    if hit.Parent:FindFirstChild("Humanoid") then
05    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
06    if plr then
07    local Points = plr:FindFirstChild("leaderstats").Points
08        Points.Value = Points.Value + 1
09        coin:Destroy()
10        end
11    end
12end
13 
14coin.Touched:Connect(ont)
Ad
Log in to vote
0
Answered by 5 years ago

You never defined Points.

01local coin = script.Parent
02 
03function ont(hit)
04    local player = hit.Parent and game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
05    local ls = player and player:FindFirstChild('leaderstats')
06    local points = ls and ls:FindFirstChild('Points')
07 
08    if points ~= nil then
09        points.Value = points.Value + 1
10        coin:Destroy()
11    end
12end
13 
14workspace.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.

01local db = false
02workspace.Part.Touched:Connect(function(hit)
03    if hit.Parent:FindFirstChild("Humanoid") then
04        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
05        local stats = plr:FindFirstChild("leaderstats")
06        if not db then
07            db = true
08            stats.Points.Value = Points.Value + 1
09            wait(3)
10            db = false
11        end
12    end
13end)

Answer this question