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

(ANSWERED) Script Cannot Detect A Tool in StarterGear?

So i have a script:

local Data = script.Parent.Parent.Setting
local Search = Data.Tool.Value
local Tool = game.ServerStorage.SHOP[Search]
local Price = Data.Price.Value
local Level = Data.Level.Value
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	if Player.leaderstats.Coin.Value >= Price and Player.leaderstats.Level.Value >= Level then
		if not Player.StarterGear:FindFirstChild(Tool) then
			Player.leaderstats.Coin.Value = Player.leaderstats.Coin.Value - Price
			local Give = Tool:Clone()
			local Give2 = Tool:Clone()
			Give.Parent = Player.Backpack
			Give2.Parent = Player.StarterGear
			print("Player "..Player.Name.." Buyed "..Tool.Name)
		end
	end
end)

It keep Cloning the item even i already have it!

Please Help!

2 answers

StarterGear is a service meant to replicate tools to players' Backpacks. It is not a descendant of the player itself, but rather a child of game, the DataModel. You're assuming there is something named StarterGear within the player which, according to your data, doesn't exist.

I'm pretty sure you meant to use Backpack instead of StarterGear, and if so it's a rookie mistake.

3 comments

0

Actually, in current Roblox every player gets their own StarterGear

0

Ok, ill try it!

0

Its not working :(

Re-Write

So i decided to Re-Write the Script and its working!

New Script:

local Data = script.Parent.Parent.Setting
local Price = Data.Price.Value
local Search = Data.Tool.Value
local Level = Data.Level.Value
local Item = game.ServerStorage.SHOP[Search]
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local Leaderstats = Player.leaderstats
local PlayerLevel = Leaderstats.Level.Value
local PlayerCoin = Leaderstats.Coin.Value

script.Parent.MouseButton1Click:Connect(function()
	if Player.Backpack:FindFirstChild(Search) then
		print(Player.Name.." Already Buyed "..Search)
	else
		if PlayerLevel >= Level and PlayerCoin >= Price then
			PlayerCoin = PlayerCoin - Price
			PlayerLevel = 2
			local Give = Item:Clone()
			local Give2 = Item:Clone()
			Give.Parent = Player.StarterGear
			Give2.Parent = Player.Backpack
			print("Player "..Player.Name.." Purchased "..Search)
		end
	end
end)

Thx for Reading!

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