Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a Give "item" based on player level?

Asked by 6 years ago
Edited 6 years ago

I am trying to give items as players get to certain levels. I am stuck on the code, and can't seem to get the Player and player leader stats player level to call properly

This is Code I have been working on Thanks for the help in advance.

local player = game.Players:GetPlayers()
 local leaderstats = player.leaderstats()
 local level = leaderstats.level()

local tool = game.ServerStorage.LinkedSword

function onPlayerSpawned(player)
  if player:Level (level) >= 1 then 
    tool:Clone().Parent = player.Backpack
  end
end

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

2 answers

Log in to vote
0
Answered by
dirk2999 103
6 years ago

That script was all over. Many unnecessary parentheses. This script should work just fine.

game.Players.PlayerAdded:connect(function(player)
    player:WaitForChild("leaderstats") -- Make sure leaderstats is there
    if player.leaderstats.level.Value >= 0 then -- Check level
        game.ServerStorage.LinkedSword:clone().Parent = player.Backpack -- Clone in their backpack
        game.ServerStorage.LinkedSword:clone().Parent = player.StarterGear -- Clone in their starter gear so they spawn with it everytime
    end
end)
0
Thanks I put that in the script and didnt receive any red errors in the Console but player does not receive the item. I will look into that later today when I get off work. Thanks again for helping. ZombieJd75 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Big thanks to dirk2999 Got it working on the one item. I had to Wait to the script. Looks like this now

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

Not tonight I can start adding more items and levels. I tried to give you an upvote but it won't let me I don't have 25 rep yet.

Answer this question