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.
01 | local coin = script.Parent |
02 |
03 | function ont(hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | Points.Value = Points.Value + 1 |
06 | coin:Destroy() |
07 | end |
08 | end |
09 |
10 | game.Workspace.Part.Touched:connect(ont) |
Use Script and put into the part u want to collect
01 | local coin = script.Parent |
02 |
03 | function 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 |
12 | end |
13 |
14 | coin.Touched:Connect(ont) |
You never defined Points.
01 | local coin = script.Parent |
02 |
03 | function 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 |
12 | end |
13 |
14 | workspace.Part.Touched:connect(ont) |
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.
01 | local db = false |
02 | workspace.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 |
13 | end ) |