Specific value of leaderboards give a item

Hello,

I need script what check when player joined in my obby if is example Prestige 5 in leaderboard and give him a some item. If is 6 Prestige other item + etc.

I show “example” what i find and try but this now work!:

game.Players.PlayerAdded:connect(function(player)
    player:WaitForChild("leaderstats") -- Make sure leaderstats is there
    if player.leaderstats.Prestige.Value >= 5 then -- Check level
        game.ServerStorage.Snowball:clone().Parent = player:WaitForChild("Backpack")
 -- Clone in their backpack
        game.ServerStorage.Snowball:clone().Parent = player.WaitForChild("StarterGear") -- Clone in their starter gear so they spawn with it everytime
    end
end)

Thanks for all help and scripts!

2 Likes

I recommend that you put the Tools in the Server Storage, otherwise cheaters can directly copy the tool and give it to themselves

*You just edited your message sorry ;3

1 Like

Can you clarify what is your error? The error display in console

1 Like

23:17:45.476 - ServerScriptService.prestigift:5: attempt to compare number and string

23:17:45.476 - Stack Begin

23:17:45.477 - Script ‘ServerScriptService.prestigift’, Line 5

23:17:45.477 - Stack End

I think your value Prestige is considerate to be a “string” and not a “int”

Try adding a “IntValue” in the leaderstats not a “StringValue”

You should use DataStore instead, and you are not setting leaderstats when the player joins. Also like @Med367367 said, maybe the Presitige Value is a string. You can fix this with tonumber()
Hope this helps

3 Likes
local Prestige = Instance.new("IntValue")
Prestige.Name = "Prestige"
Prestige.Parent = Stats
Prestige.Value = 0	

this should fix it. or

game.Players.PlayerAdded:connect(function(player)
player:WaitForChild("leaderstats") -- Make sure leaderstats is there
if tonumber(player.leaderstats.Prestige.Value) >= 5 then -- Check level
    game.ServerStorage.Snowball:clone().Parent = player:WaitForChild("Backpack")
 -- Clone in their backpack
        game.ServerStorage.Snowball:clone().Parent = player.WaitForChild("StarterGear") -- Clone in their starter gear so they spawn with it everytime
    end
end)
1 Like

Ok tryed now, console not said any error. And still backpack dont have this tool.
Btw tool normaly working and when i manualy drag to StarterPack be there in game so dont know.

It is normal that if you put them in the Starter Pack it does not appear immediately, Here is the function of StarterPack.StarterPack | Documentation - Roblox Creator Hub
For doing this simple, just make the player re-spawn after

if tonumber(player.leaderstats.Prestige.Value) >= 5 then -- Check level
    player.CharacterAdded:Connect(function(obj)
        local tool =  game.ServerStorage.Snowball:clone()
        tool.Parent = WaitForChild("Backpack")
    end)
end

This should add the tool everytime they die or spawn
Hope this helps

This will work but if there are a lot of tools to verify this is include a lot of “if” and this can by bad at a certain time. I think is more a good idea to set it in the player StarterGear but this is only my opinion

1 Like

Is the starterPack local or server? If it local then put it in but if it is on the server then don’t.
Sorry

Sorry, is StarterGear i edited my message x’)
StarterGear = Client (Current Player)
starterPack = Server

1 Like

I am pretty sure this is incorrect. StarterGear and StarterPack are both on the server (although I believe only StarterGear is replicated to the client). StarterGear is basically a starter pack only for the Player it is parented to. StarterPack gives every player in the game the tools in it when their character respawns.

1 Like

Nope like i said in PM solution not work.

I sending here gamepass script part what i used to check if Product buyed.
Maybe in this script you find some what working better to backpack this.
This script use “lighting” part as Storage :slight_smile:

Here is example:

local Lighting = game:GetService("Lighting")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamepassId = 0000000 --Put the ID of the asset here
local toolNames = {"SpeedCoil"} --Must be in lighting
local toolsParent = Lighting

local function onPlayerAdded(player)
	local function onCharacterAdded(character)
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
			for i = 1, #toolNames do
				local tool = toolsParent:FindFirstChild(toolNames[i])
				if tool then
					local clone = tool:Clone()
					clone.Parent = player.Backpack
				end
			end
		end
	end

	if player.Character then
		onCharacterAdded(player.Character)
	end
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

If someone have some idea how to do that please post some script. Thank you guys.

You need to wait for the character. Add:

player.CharacterAdded:Wait()

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:Wait()
    player:WaitForChild("leaderstats") -- Make sure leaderstats is there
    if player.leaderstats.Prestige.Value >= 5 then -- Check level
        game.ServerStorage.Snowball:clone().Parent = player:WaitForChild("Backpack")
 -- Clone in their backpack
        game.ServerStorage.Snowball:clone().Parent = player.WaitForChild("StarterGear") -- Clone in their starter gear so they spawn with it everytime
    end
end)

This should do it.

I now know why the script is not working.

You put .WaitForChild("StarterGear") and not :WaitForChild("StarterGear")
we all fell in this hole.
Hopes this helps.

Any of this scripts not working.