✓ Accepted answer
###The problem with your script is you're attempting to access ServerStorage from the client, when the service is server-side only, hence the name ServerStorage. Also, you should be cloning on the server as the changes will not replicate if all under a local script. You'll need a RemoteEvent to access ServerStorage.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CloneTool = ReplicatedStorage:WaitForChild("CloneTool")
local plr = game:GetService("Players").LocalPlayer
local primaryGun = plr.Equipment.PrimaryGun
script.Parent.MouseButton1Click:Connect(function()
CloneTool:FireServer(primaryGun.Value)
end)
###Server code, in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Guns = ServerStorage:WaitForChild("Guns")
local CloneTool = ReplicatedStorage:WaitForChild("CloneTool")
CloneTool.OnServerEvent:Connect(function(plr, toolName)
local char = plr.Character
if not plr:FindFirstChild(toolName, true) and not char:FindFirstChild(toolName) then
local gun = Guns[toolName]:Clone()
gun.Parent = plr.Backpack
gun:Clone().Parent = plr.StarterGear
end
end)
###Also, it "worked" in studio because you used Play Solo, and Play Solo is the server and client combined. There is no separation. This is why you were able to access ServerStorage from a local script. They will most likely be separated in the future. For now, don't use Play Solo to test your scripts. Use test/local servers to do this.
2 comments
06:51:30.861 - ServerScriptService.Script:12: attempt to index global 'player' (a nil value)
Sorry lol