****Whenever the player finishes the obby they will step on a part which will award XP. But I made an error and I need help. I made EXP a number value so its not part of the leaderstats folder. So it would be player.EXP.Value instead of player.leaderstats.EXP.Value
1 | local Player = game.Players.LocalPlayer |
2 | local Award = script.Parent |
3 | local exp = Player.EXP |
4 |
5 | Award.Touched:connect( function (player) |
6 | if player and player.Parent and player.Parent:FindFirstChild( 'Humanoid' ) then |
7 | exp.Value = exp.Value + 15 |
8 | end |
9 | end ) |
By writing for player.Parent you are referring to Players folder, and that's a mistake. You should also refer to the Player, and not the character.
Here is something I would prefer you use.
1 | script.Parent.Touched:connect( function (hit) -- This makes the function happen when the brick is touched |
2 | if game.Players:GetPlayerFromCharacter(hit.Parent) then -- The function GetPlayerFromCharacter refers to the Player, we use an if statement to makes sure it's a real player, |
3 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- A variable referring to the Player |
4 | if player:FindFirstChild( "leaderstats" ) then -- Check if leaderstats exist |
5 | player.leaderstats.exp.Value = player.leaderstats.exp.Value + 15 -- increases the value |
6 | end |
7 | script.Parent:Destroy() -- This is to remove the part that is touched, in case you don't want the player to touched again |
8 | end |
9 | end ) |
The Character is the part of the player that is under the Player folder The Player is the part of the player that is under Workspace