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

How do I resolve the issue consisting of "StarterGear is not a valid member of Player?"

My code thus far:

script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Firebrand") local price = 25 local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats")

if stats.Souls.Value>=price then
	stats.Souls.Value = stats.Souls.Value - price
	local cloned = item:Clone()
	cloned.Parent = player.Backpack
	cloned.Parent = player.StarterGear
end	

end)

I am looking forward to somebody's response.

Thank you, Sqookly

2 comments

0

WaitForCHild u use on leaderstats but not on StarterGear ??? if u made a own folder StarterGear maybe its not made yet and the script has to wait on it, or use FindFirstChild like local SG = player:FindFirstChild("StrarterGear") and do if SG then cloned.Parent = SG end

0

Why are you parenting it to the StarterPack AFTER the Backpack? You do realize that everything in StarterGear gets cloned to the Backpack, right?

3 answers

well, starter pack is not inserted into a player when the game starts; instead, a new folder named "Backpack" is made and inserted into the player to hold all the equipable tools;

so lets say i have a tool in starterpack named "gun"

to access it; i would have to do: player.Backpack.gun

Create a StarterGear

You could create a StarterGear if it doesn't exist. Just check if it exists and if it doesn't, make a new one.

local StarterGear = Player:FindFirstChildOfClass('StarterGear')
if (not StarterGear) then
	StarterGear = Instance.new('StarterGear', Player)
end

Create a custom system

More effort, but will solve your problem and can be more reliable (like if you want to put the tools in a certain order).

Just save the player's tools using a dictionary or some other method and clone it when they spawn in.

--saving tools as starter
local savedTools = {}

savedTools[Player] = {Item1, Item2, Item3}

--spawning tools
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local tools = savedTools[player]
		for i, tool in pairs(tools) do
			--clone in backpack
		end
	end)
end)

1 comment

0

i did it with a bool value. if its true clone the tool to the backpack. but this is also a way to do it

script.Parent.MouseButton1Click:connect(function() 
	local RS = game:GetService("ReplicatedStorage") 
	local item = RS:WaitForChild("Firebrand") 
	local price = 25 
	local player = game.Players.LocalPlayer 
	local stats = player:WaitForChild("leaderstats")
	local SG = player:WaitForChild("StarterGear") or player:FindFirstChild("StarterGear")

-- when u do FindFirstChild u can do

--< if SG then
	--code here
     else
	SG = player:WaitForChild("StarterGear")  -- try to find it again

	--other code to start over on the if SG then
--   end >


	if stats.Souls.Value>=price then
		stats.Souls.Value = stats.Souls.Value - price
		local cloned = item:Clone()
		cloned.Parent = player.Backpack
		cloned.Parent = SG
	end
end)

1 comment

0

thank for the explain admin :D

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