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

Whats wrong with my script?

Hi I was scripting this game and I came across an error in the output that said "ClassicSword is not a valid member of StarterGear." Can you help?

price = 550
plr = game.Players.LocalPlayer
debounce = false
if plr.StarterGear.ClassicSword.Configurations.LungeDamage == 50 then
	script.Parent.Active = false
	script.Parent.Visible = false
elseif plr.StarterGear.ClassicSword.Configurations.LungeDamage > 50 or plr.StarterGear.ClassicSword.Configurations.LungeDamage < 50 then
	script.Parent.MouseButton1Click:connect(function()
   if debounce then return end 
    local v = plr.leaderstats.Credits
    debounce = true 
    if v.Value >= price then
        plr.StarterGear.ClassicSword.Configurations.LungeDamage.Value = 50
        v.Value = v.Value - price
        script.Parent.Parent.Buy.Visible = true
        wait(0.2) 

        for i = 0.1,1,0.1 do
            wait(0.1)
            script.Parent.Parent.Buy.TextTransparency = i
        end

        script.Parent.Active = false
        script.Parent.Visible = false
        script.Parent.Parent.upgrade2.Active = true
        script.Parent.Parent.upgrade2.Visible = true
        script.Parent.Parent.error.Position = UDim2.new(0, 200, 0, 100)
        script.Parent.Parent.Buy.Position = UDim2.new(0, 200, 0, 100)

        print('You bought the item!')
    else
	
    print ('Cant buy item!')
        script.Parent.Parent.error.Visible = true
script.Parent.Parent.Parent.Frame.error2.Text = "You need "..550 - plr.leaderstats.Credits.Value.." more Credits to buy this!"
            script.Parent.Parent.error.TextTransparency = 0
			script.Parent.Parent.error2.TextTransparency = 0
			wait(2)
			        for i = .1,1,.1 do 
wait(0.1)
            script.Parent.Parent.error.TextTransparency = i
			script.Parent.Parent.error2.TextTransparency = i			
        end
    end
debounce = false
end)
end


1 answer

If your sword is in ServerStorage, then you'd need to clone it in to the backpack like this: game.ServerStorage.ClassicSword:Clone().Parent = plr.Backpack This will not work with FilteringEnabled on if you have it on. Therefore, you should really move it to ReplicatedStorage so it becomes this: game.ServerStorage.ReplicatedStorage.ClassicSword:Clone().Parent = plr.Backpack Also, it's really good practice to make a variable for the sword, like this:

local sword = plr.Backpack:FindFirstChild("ClassicSword")
--Now I can use "sword" without having to use the whole path all the time!
if sword then
	print("Yay! This worked!")
end

You can also do this for other objects too, for example the error object you seem to use a lot.

7 comments

0

backpack didn't work

0

"Backpack", not "backpack"

0

Yes I know it still didn't work :(

0

It still says sword is not a valid member of Backpack

0

Is ClassicSword a member of StarterPack?

1

Use WaitForChild instead of indexing it directly if you're expecting it to be there and it isn't yet.

0

^

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