I am currently trying to script my own GUI shop. When one presses script.Parent, an item - in this case the player should get “Sword”.
It’s a LocalScript inside a TextButton.
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function(click)
game.ReplicatedStorage.Sword:Clone().Parent = player:WaitForChild("Backpack")
end)
When I test it and press the TextButton, I get the sword I pasted into game.ReplicatedStorage but nothing happens when I press my left mouse button.
When I copy&paste “Sword” from game.ReplicatedStorage to game.Workspace during a test, I can also pick it up by touching it but I can’t use it either. When I paste “Sword” into game.Workspace before starting the test, it works well.
Does copying the sword into ReplicatedStorage break the scripts inside it? Does anyone have an idea on what’s going on?
Thanks!
Abalone
Edit: Just realized that the Sword is also only visible locally. I will try to figure it out and then post the anwser here.
Only server should have ability to give the sword, u can achieve this with remote events, where u send a message from the local to server and server checks if player has enough money and if hes not already the owner of the item
Always clone items from ServerStorage, ReplicatedStorage is archivable by the local.
You will have to use RemoteEvents and connect client-side on button pressed to the server and then on the server you will have to clone the sword and parent it inside of player’s backpack.
You should not handle player/item replication over the client as it is not replicated to all players. You can get through this problem using remote evens/functions as found on the roblox WIKI:
For your case, you should fire an event (With the player) once the player presses the button. Then the server retrieves it with an onserverevent/onserverinvoke and then you handle the cloning there, cloning it to the player.
This fires the remote even when the button is pressed, sending the name of the requested gear.
In game.ServerScriptService I’ve created a second, “normal” script:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local gear = game.ServerStorage.Gear
RemoteEvent.OnServerEvent:Connect(function(player,gearName) --Here I get the Player that clicked and the gearName
local Backpack = player:FindFirstChild("Backpack")
local gear = gear:FindFirstChild(gearName)
gear:Clone().Parent = Backpack
end)
My Tools are stored in a folder within game.ServerStorage