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

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

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

✓ Accepted answer

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)

4 comments

0

This looks promising

0

Thank you so much! I know understand Clone()!

0

Wow this is sad he gets credit even though I made mine first...

0

lol @ above

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

6 comments

0

2nd code example is incorrect. You can use .Parent = after a :Clone().

0

He didnt though...

0

It is correct xD

0

And yes u can but read his script he isnt using the clone smarty...

0

Its correct l0l

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().

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