Hi, So I am making a simulator. I'm trying to make it as original as I can, but the problem is with my shop. The functions it is meant to have is that it clones a tool from ReplicatedStorage into the players backpack, but when I playtest it in studio wherever I put it, it gets hidden and in the output, it says it's not a valid member of ReplicatedStorage. I don't know what to do, I have looked at tutorials and followed their scripts but the tool always gets deleted. Here is my cloning script if you need it.
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() local tool = script.Tool:Clone() tool.Parent = player.Backpack print("stick added to backpack") end)
That is in a LocalScript in StarterGUI. I haven't really done cloning before so I'm new to this. Any help appreciated!
When you learn scripting, one of most important rules: Never copy code. Your code couldnt just match the same conditions and wont work in your enviroment, exactly as here. As I understood this script is parented to some UI and when you click it you obtain the tool. But UI's are parented to Player.PlayerGui. And yet, you use script.Tool to get the tool when you said its in replicated storage.
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() local tool = game.ReplicatedStorage.Tool:Clone() -- this line was wrong tool.Parent = player.Backpack print("stick added to backpack") end)