script.Parent.MouseButton1Click:connect(function() if game.Players.LocalPlayer.Equipment.PrimaryGun.Value == "Startergun" then game.ServerStorage.Guns.Startergun:Clone().Parent = game.Players.LocalPlayer.Backpack else if game.Players.LocalPlayer.Equipment.PrimaryGun.Value == "Rank2Gun" then game.ServerStorage.Guns.Rank2:Clone().Parent = game.Players.LocalPlayer.Backpack end end end)
its in a local script all the vaules are right works in studio but not in game
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") -- remote event local plr = game:GetService("Players").LocalPlayer local primaryGun = plr.Equipment.PrimaryGun -- getting primarygun object script.Parent.MouseButton1Click:Connect(function() -- :connect is deprecated, use :Connect CloneTool:FireServer(primaryGun.Value) -- make sure the Value is spelt like the gun name end)
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 -- I don't think you'd want users to have multiple guns. If you do, just get rid of this local gun = Guns[toolName]:Clone() gun.Parent = plr.Backpack gun:Clone().Parent = plr.StarterGear end end)
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.