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

Script not giving the desired tool from a value?

I am trying to make a script that gives a player a tool based on a value. For some reason, it does not give the player the tool.

game.Players.PlayerAdded:Connect(function(plr)
	local rep = game:GetService("ReplicatedStorage")
	local tools = rep:FindFirstChild("Tools")
	local redbull = plr:FindFirstChildWhichIsA("IntValue")
	
	if redbull == 0 then
		print("No value")
	else
		wait(1)
		plr.Backpack:FindFirstChild("RedBull"):Destroy()
		for i,v in pairs(tools:GetChildren()) do
			local tool = v
			if tool.Stats.BullValue.Value == redbull then
				tool:Clone().Parent = plr.Backpack
			end
		end
	end
end)

1 answer

I found out why this was happening. Here is the updated script

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local rep = game:GetService("ReplicatedStorage")
		local tools = rep:FindFirstChild("Tools")
		local redbull = plr:FindFirstChild("Redbull")

		if redbull.Value == 0 then
			print("No value")
		else
			wait(1)
			plr.Backpack:FindFirstChild("RedBull"):Destroy()
			for i,v in pairs(tools:GetChildren()) do
				local tool = v
				if tool.Stats.BullValue.Value == redbull.Value then
					tool:Clone().Parent = plr.Backpack
				end
			end
		end
	end)
end)

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