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

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

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

2 comments

0

You want: local pu = game.ReplicatedStorage.Potion and local pu2 = game.ReplicatedStorage.Potion:Clone()

0

you should put "break" at the end of the if statement to stop the loop

2 answers

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

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

1 comment

0

You gave no context, and you shouldn't do it in a local script

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