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

Whats wrong with my script?

Asked by 9 years ago

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

Log in to vote
0
Answered by
DevChris 235 Moderation Voter
9 years ago

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.

0
backpack didn't work docrobloxman52 407 — 9y
0
"Backpack", not "backpack" DevChris 235 — 9y
0
Yes I know it still didn't work :( docrobloxman52 407 — 9y
0
It still says sword is not a valid member of Backpack docrobloxman52 407 — 9y
View all comments (3 more)
0
Is ClassicSword a member of StarterPack? DevChris 235 — 9y
1
Use WaitForChild instead of indexing it directly if you're expecting it to be there and it isn't yet. 1waffle1 2908 — 9y
0
^ DevChris 235 — 9y
Ad

Answer this question