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

:Clone() LocalScript.Parent = Player.Backpack Not Cloning?

Asked by 5 years ago

Ok my basic shop script needs to send a script to the player's backpack. (I have starter gear too cause that's how I remember to make these kinda scripts) But when the player buys the item, it sends the script, instead of a copy. If another player tries to buy theitem it says "SlvrEnable Is not a valid member of replicated storage" and they cant get it. Any idea on what I'm doing wrong? If its filtering enabled I will cry cause I'm good at it XD.

SlvrEnable = game.ReplicatedStorage.SlvrEnable
game.ReplicatedStorage.SlvrPurchase.OnServerEvent:Connect(function(Player)
    if Player.leaderstats.Coins.Value >= 25 then

    Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - 25
    Player:WaitForChild ("Backpack")
    game.ReplicatedStorage.SlvrEnable:Clone()SlvrEnable.Parent = Player.Backpack
    game.ReplicatedStorage.SlvrEnable:Clone()SlvrEnable.Parent = Player.StarterGear
    else
        print ("not enough money")
end
end)

2 answers

Log in to vote
2
Answered by
green271 635 Moderation Voter
5 years ago

There is an error on lines 7 and 8. You don't put the name after :Clone(), just the .Parent

Updated Code:

    local SlvrEnable = game.ReplicatedStorage.SlvrEnable
    game.ReplicatedStorage.SlvrPurchase.OnServerEvent:Connect(function(Player)
        if Player.leaderstats.Coins.Value >= 25 then

        Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - 25
        local Backpack = Player:WaitForChild ("Backpack")
        game.ReplicatedStorage.SlvrEnable:Clone().Parent = Backpack
        game.ReplicatedStorage.SlvrEnable:Clone().Parent = Player.StarterGear
        else
            print ("not enough money")
    end
    end)
0
This looks promising AswormeDorijan111 531 — 5y
0
Thank you so much! I know understand Clone()! DatRainbowTee 49 — 5y
0
Wow this is sad he gets credit even though I made mine first... NYDynamics 71 — 5y
0
lol @ above green271 635 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

Well, you treated the variable 'SlvrEnable' as it has been cloned in two places...

game.ReplicatedStorage.SlvrEnable:Clone()SlvrEnable.Parent = Player.Backpack
 game.ReplicatedStorage.SlvrEnable:Clone()SlvrEnable.Parent = Player.StarterGear

You have made the Clone but you are not using it I would do this...

    local Clone = SlvrEnable:Clone()
    Clone.Parent = Player.StarterGear

Also... you didnt use the variable you defined which is a waste of code I would use

SlvrEnable = game.ReplicatedStorage.SlvrEnable
0
2nd code example is incorrect. You can use .Parent = after a :Clone(). green271 635 — 5y
0
He didnt though... NYDynamics 71 — 5y
0
It is correct xD NYDynamics 71 — 5y
0
And yes u can but read his script he isnt using the clone smarty... NYDynamics 71 — 5y
View all comments (2 more)
0
Its correct l0l DrDecor 0 — 5y
0
The 2nd paragraph I interpreted as him saying that you can ONLY use it the way he did. Which is why I said it was incorrect, as you can put .Parent at the end of a :Clone(). green271 635 — 5y

Answer this question