Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get my OBBY stages to add up on the leaderboard?

I got a leaderboard to work which shows the world and stage, Now I want it that when I jump on a checkpoint the stage goes up on the leaderboard and when I die I spawn at the Checkpoint but I can't get it to work. I neither respawn at the checkpoint nor does the stage go up on the leaderboard.

Here is the code for the leaderboard:

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Model")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player 
	local money = Instance.new("IntValue") 
	money.Name = "World"  
	money.Value = 1 
	money.Parent = leaderstats 
	local money = Instance.new("IntValue") 
	money.Name = "Stage" 
	money.Value = 1 
	money.Parent = leaderstats 
end)

This is the code at the Spawnpoint/Checkpoint:

function onTouched(part)
		    name = script.Parent.Name
		        local h = part.Parent:FindFirstChild("Humanoid")
		    if h ~= nil then
			        char = h.Parent
			        player = char:GetPlayerFromCharacter(char)
			            if player ~= nil then
				                leaderstats = player.FindFirstChild("leaderstats")
				                if leaderstats ~= nil then
					                    stage = leaderstats:FindFirstChild("Stage")
					                    if stage ~= nil then
						                        stage.Value = name
					end
				 end
			 end
		 end
	end	
end

script.Parent.Touched:connect(onTouched) -- Links event to function

The only error I get is Workspace.1.Checkpoint System:18 Expected , got 'end' But I don't understand what it means...

The World is for when I add multiple worlds to the obby but I am not that far yet.

I hope someone can help. Thank you in advance!

1 answer

✓ Accepted answer

Your mistakes are : You make the same variable twice

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player 
    local money = Instance.new("IntValue") 
    money.Name = "World"  
    money.Value = 1 
    money.Parent = leaderstats 
    local money = Instance.new("IntValue")  -- You make the same variable twice, change with something
    money.Name = "Stage" 
    money.Value = 1 
    money.Parent = leaderstats 
end)

change the script like this :

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player 
    local money = Instance.new("IntValue") 
    money.Name = "World"  
    money.Value = 1 
    money.Parent = leaderstats 
    local stage = Instance.new("IntValue")  -- I change the variable to "stage", you can also change it whatever you want
    stage.Name = "Stage" 
    stage.Value = 1 
    stage.Parent = leaderstats 
end)

second, you are not using " : " at this script

function onTouched(part)
            name = script.Parent.Name
                local h = part.Parent:FindFirstChild("Humanoid")
            if h ~= nil then
                    char = h.Parent
                    player = char:GetPlayerFromCharacter(char)
                        if player ~= nil then
                                leaderstats = player.FindFirstChild("leaderstats") --This should be (player:FindFirstChild("leaderstats"))

                                if leaderstats ~= nil then
                                        stage = leaderstats:FindFirstChild("Stage")
                                        if stage ~= nil then
                                                stage.Value = name
                    end
                 end
             end
         end
    end 
end

script.Parent.Touched:connect(onTouched) -- Links event to function

so the script would be like this

function onTouched(part)
           local name = script.Parent.Name
                h = part.Parent:FindFirstChild("Humanoid")
            if h ~= nil then
                   char = h.Parent
                    player = char:GetPlayerFromCharacter(char)
                        if player ~= nil then
                                leaderstats = player:FindFirstChild("leaderstats")
                                if leaderstats ~= nil then
                                        stage = leaderstats:FindFirstChild("Stage")
                                        if stage ~= nil then
                                                stage.Value = name
                    end
                 end
             end
         end
    end 
end

script.Parent.Touched:connect(onTouched) -- Links event to function

let me know if there is still any error

3 comments

0

I changed the scripts as you said but still when I jump on the checkpoint it doesn't respawn me there if I die. Maybe I am doing something wrong in studio itself in the porperties?

0

you can check this link for more tutorial, https://www.youtube.com/watch?v=Aa83VYif6VA

0

you can also make this answer as a correct answer if you think this help you with your problem

This discussion is preserved as it was. New answers, comments, and votes are closed.