Here's the script:
local me = game.Players.iiiAmericanLight local chr = me.CharacterAdded:Wait() local swr = game.ServerStorage["Meliodas Sword"] local pfr = game.ServerStorage.PurgatoryFlame local sw = swr:Clone() local pf = pfr:Clone() sw.Parent = me.Backpack pf.Parent = me.Backpack
I hope this helps. It will replace some of your references so it waits for the child (yields until the child exists). Note: If you're using this in a LocalScript, you can't access ServerStorage from the LocalScript !!! You may want to use a RemoteEvent for it. If you are doing this for test purposes (Not recommended as the client can get the tools without any problem), you can try ReplicatedStorage, a container where both server and client replicate with.
local me = game.Players.iiiAmericanLight local chr = me.Character or me.CharacterAdded:Wait() local swr = game:GetService("ServerStorage"):WaitForChild("Meliodas Sword") local pfr = game:GetService("ServerStorage"):WaitForChild("PurgatoryFlame") local sw = swr:Clone() local pf = pfr:Clone() sw.Parent = me.Backpack pf.Parent = me.Backpack
But, I'm sure you want it for practical purposes. Let's setup first your local side script. I'll explain the process below the codes. Here's the Local Script
-- LocalScript local event = game:GetService("ReplicatedStorage"):WaitForChild("ClientRequest") local player = game.Players.LocalPlayer if player.Name == "iiAmericanLight" then -- you can try with userid instead, so it works regardless when you change of username. event:FireServer() end
Here's the server script
-- ServerScript local event = Instance.new("RemoteEvent") event.Parent = game:GetService("ReplicatedStorage") event.Name = "ClientRequest" event.OnServerEvent:Connect(function(player) local swr = game:GetService("ServerStorage"):WaitForChild("Meliodas Sword") local pfr = game:GetService("ServerStorage"):WaitForChild("PurgatoryFlame") local sw = swr:Clone() local pf = pfr:Clone() sw.Parent = player.Backpack pf.Parent = player.Backpack end)
What this actually does is, when the LocalScript runs (Supposedly you're using this LocalScript inside StarterGui), it assigns the player variable to the local player. then, through the if statement, it checks if the player's name is equal to the name you supposedly want to give such feature. and if it is, it then fires to the server through the remote connection we set up. Then in the ServerScript, it receives the interaction and since all client connections to the server return the player who effectuated the connection, we can use this for our server-side code. Now we can access ServerStorage and do our stuff! I've also removed your character variable as it wasn't needed but you can add it in your server-side script. The final stage is that the script gets the tools from the serverstorage, clones it and locates them in your Backpack. This also works with FilteringEnabled, as the work of each side belongs to their respective sides, that's it: server-sided tasks (accessing ServerStorage and distributing objects) must be in the server script, and local-side tasks (processing the request, setting up the stuff), must be in the local script! I hope it helped.