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

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

Asked by 5 years ago

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

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 User#27824 0 — 5y
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? DeceptiveCaster 3761 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago

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)
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 User#27824 0 — 5y
Log in to vote
-1
Answered by 5 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
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)
0
thank for the explain admin :D User#27824 0 — 5y

Answer this question