Skip Level Product Won't Work?
Asked by
5 years ago Edited 5 years ago
I spent an hour making a skip level button for my friend's game to figure out it doesn't work. When I go from 0 to 1 it works, then when I buy it to go to the 2nd level I go to the 3rd level.
Enough talking, here's the code.
01 | local MS = game:GetService( "MarketplaceService" ) |
02 | function MS.ProcessReceipt(receipt) |
03 | local Player = tostring (receipt.PlayerId) |
04 | local character = game.Players:GetPlayerByUserId(receipt.PlayerId).Character |
05 | local CheckpointData = game.ServerStorage:FindFirstChild( "CheckpointData" ) |
06 | local PlayerData = CheckpointData:FindFirstChild(Player) |
08 | local A = tostring (PlayerData.Value) |
09 | local LevelWord = "Level" |
10 | local Number = string.sub(A,#LevelWord+ 1 ,#A) |
11 | local NumberA = tonumber (Number) |
12 | local NumberB = NumberA+ 1 |
13 | local LevelPart = game.Workspace:FindFirstChild( "Level" ..NumberB) |
14 | PlayerData.Value = LevelPart |
15 | character:MoveTo(LevelPart.Position + Vector 3. new(math.random(- 4 , 4 ), 4 , math.random(- 4 , 4 ))) |
17 | local New = Instance.new( "ObjectValue" ,CheckpointData) |
18 | New.Name = tostring (receipt.PlayerId) |
19 | New.Value = game.Workspace.Level 1 |
20 | character:MoveTo(game.Workspace.Level 1. Position + Vector 3. new(math.random(- 4 , 4 ), 4 , math.random(- 4 , 4 ))) |
Edit: In case you need it, here is the checkpoint script.
01 | local Players = game:GetService( "Players" ) |
02 | local ServerStorage = game:GetService( "ServerStorage" ) |
04 | local checkpoint = script.Parent |
06 | function onTouched(hit) |
07 | if hit and hit.Parent and hit.Parent:FindFirstChildOfClass( "Humanoid" ) then |
08 | local player = Players:GetPlayerFromCharacter(hit.Parent) |
09 | local checkpointData = ServerStorage:FindFirstChild( "CheckpointData" ) |
10 | if not checkpointData then |
11 | checkpointData = Instance.new( "Folder" ) |
12 | checkpointData.Name = "CheckpointData" |
13 | checkpointData.Parent = ServerStorage |
16 | local userIdString = tostring (player.UserId) |
17 | local checkpointValue = checkpointData:FindFirstChild(userIdString) |
18 | if not checkpointValue then |
19 | checkpointValue = Instance.new( "ObjectValue" ) |
20 | checkpointValue.Name = userIdString |
21 | checkpointValue.Parent = checkpointData |
23 | player.CharacterAdded:connect( function (character) |
25 | local storedCheckpoint = ServerStorage.CheckpointData [ userIdString ] .Value |
26 | character:MoveTo(storedCheckpoint.Position + Vector 3. new(math.random(- 4 , 4 ), 4 , math.random(- 4 , 4 ))) |
30 | checkpointValue.Value = checkpoint |
34 | checkpoint.Touched:Connect(onTouched) |