1 | local PartTouch = 1 |
2 |
3 | game.Workspace.Part.Touched:Connect( function (hit) if hit.Parent:FindFirstChild( "Humanoid" ) then if PartTouch = = |
4 | 1 then |
5 | local keys = hit.leaderstats.keys keys.Value = keys.Value + 1 |
6 |
7 | end |
8 | end |
9 | end ) |
and IT GIVES ME ERRORS
Hello.
You cannot have spaces be used like that when you are trying to add to values.
I also recommend adding a Debounce
to your script, so that the values aren't added more than once.
Assuming that your leaderstats is located in the Player's character, this is what the script should look like:
01 | local PartTouch = 1 |
02 | local Debounce = false |
03 |
04 | local Players = game:GetService( "Players" ) |
05 | local Cooldown = 1 -- Can be changed to how much of a cooldown you want before the part can be touched again. This is not related to changing values in the leaderstats. |
06 |
07 | local function PartTouched(Collision) |
08 | if not (Debounce) then |
09 | Debounce = true |
10 | local Humanoid = Collision.Parent:FindFirstChildWhichIsA( "Humanoid" ) |
11 | if (Humanoid) then -- Verify that whatever touched this part has a humanoid. |
12 |
13 | local Player = Players:GetPlayerFromCharacter(Collision.Parent) |
14 | if (Player) then -- Verify that whatever touched this part is a player and has a humanoid. |
15 | local Leaderstats = Player.Character.leaderstats |
Hope this works for you.