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

This is supposed to give a player a tool once they reach a certain requirement. Why doesn't it work?

Asked by 5 years ago

This is the script:

local player = game.Players.LocalPlayer

while true do
    wait(0.1)
if player.leaderstats.Level.Value >= 2
    local pu= game.ReplicatedStorage.Potion:Clone()
    local pu2 = game.ReplicatedStorage.Potion:Clone()
    pu.Parent = player.Backpack
    pu.Parent = player.StarterGear
end
end
0
You want: local pu = game.ReplicatedStorage.Potion and local pu2 = game.ReplicatedStorage.Potion:Clone() uguns663 0 — 5y
0
you should put "break" at the end of the if statement to stop the loop Gey4Jesus69 2705 — 5y

2 answers

Log in to vote
0
Answered by
Smauce 12
5 years ago

Using a while loop isn't necessary. I would suggest you use the changed event. The code to add the tool into the player's backpack is fine.

player.leaderstats.Level.Changed:Connect(function(property)
    If property == 'Value'  and property == 2 then
        local pu= game.ReplicatedStorage.Potion:Clone()
        local pu2 = game.ReplicatedStorage.Potion:Clone()
        pu.Parent = player.Backpack
        pu.Parent = player.StarterGear
    end
end
Ad
Log in to vote
-1
Answered by 5 years ago

Try using this script. Make sure it is a local script:

local player = game.Players.LocalPlayer

while true do
    wait(0.1)
local stats = player:WaitForChild("leaderstats")
if stats.Level.Value >= 2 then
    local pu= game.ReplicatedStorage.Potion:Clone()
    local pu2 = game.ReplicatedStorage.Potion:Clone()
    pu.Parent = player.Backpack
    pu.Parent = player.StarterGear
end
end
0
You gave no context, and you shouldn't do it in a local script SirDerpyHerp 262 — 5y

Answer this question