You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I have a Gui that is a list of every sword a player has unlocked. They click it they get the sword. Every time I clone the sword and parent it to backpack the sword doesn’t work.(Maybe its because I’m cloning from a Local Script). But when I pick the weapon up from the workspace and it is not a clone the tool works.
So my question is, do I have to clone using a replicated event? and if so how would I recognize the button that was pressed in the gui on the server side?
scripts below.
–Local script (InsideGui)
function WeaponRetrieve(button)
local PotentialClone = player.Backpack:FindFirstChild(button.Sword.Value)
if PotentialClone then else
for a, b in ipairs(weapons:GetDescendants()) do
if b.Name == (button.Sword.Value) then
ReplicatedStorage.WeaponClone:FireServer(button)
end
end
end
end
for i,v in pairs(sc:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
WeaponRetrieve(v)
end)
end
end
Regular Script
function WeaponClone(player)
local buttons = player.PlayerGui.Armory.ScrollingFrame
end
ReplicatedStorage.WeaponClone.OnServerEvent:Connect(WeaponClone)
Um, well first off, you can’t access a local player’s GUI on the server side, unless you reference StarterGui instead:
player.PlayerGui.SomeGui -- What you have currently, doesn't work on server
game:GetService("StarterGui").SomeGui -- Works on server
However, that’s not the smartest way to go around this (and it still doesn’t work with your current implementation), more info below.
You can’t send an Instance that only exists on the client to the server (the button in this case), ideally you don’t want to send Instance values in the first place. You should send a string of the Sword name instead. From there the server should do a :FindFirstChild() check to see if the sword exists, if so clone it into the player’s backpack.
Brief example (untested)
-- Client Sided Code:
-- Fire a string value of the weapon name to the server:
ReplicatedStorage.WeaponClone:FireServer(insertWeaponNameHere)
-- Server Sided Code:
function WeaponClone(player, weapon)
local findWep = ReplicatedStorage:FindFirstChild(weapon) -- Assuming you stored all
-- tools in RepStorage
if findWep then -- If the weapon exists, clone it to the player's backpack
local clone = findWep:Clone()
clone.Parent = player.Backpack
end
end
Lastly, another good practice (if you aren’t already) is to store tools in ServerStorage (unless you want them all instantly available to the client for view models, preloading, etc).