game.Players.PlayerAdded:Connect(function(player) print(player.Name..("Has Joined")) local ReplicatedStorage= game:GetService("ReplicatedStorage") local Buy = player.PlayerGui:WaitForChild("Gui").Main.PromptPurchase.Purchase local Cash = player:WaitForChild("leaderstats").Cash local Price = Buy.Parent.ItemPrice local Name = Buy.Parent.ItemName local GunItemName = game:GetService("ReplicatedStorage").GunItemName --GunItemName is a stringValue in ReplicatedStorage. local clonegun = ReplicatedStorage.Guns:FindFirstChild(GunItemName.Value) Buy.MouseButton1Click:Connect(function() if Cash.Value >= Price.Value then Cash.Value = Cash.Value - Price.Value print(GunItemName.Value) print("Bought") clonegun:Clone().Parent = player.Backpack -- im getting a error that says "clonegun' (a nil value)" print("Cloned") end end) end)
We've been talking in the chat feature, I'm just posting here to show you some formatting
--Create a RemoteEvent in ReplicatedStorage, title it what you want --Server side local PurchaseGun = game:GetService("ReplicatedStorage").EventName --Add guns and change prices as you wish. local GunPrices = { ["Pistol"] = 100, ["Revolver"] = 200, ["Uzi"] = 300 } PurchaseGun.OnServerEvent:Connect(function(Player, GunName) local Cash = Player:FindFirstChild("leaderstats").Cash if Cash.Value >= GunPrices[GunName] then Cash.Value = Cash.Value - GunPrices[GunName] print(GunName) print("Bought") local clonegun = ReplicatedStorage.Guns:FindFirstChild(GunName) clonegun:Clone().Parent = Player.Backpack -- im getting a error that says "clonegun' (a nil value)" print("Cloned") end end) end)
Then in a LocalScript, parented to the GUI
local PurchaseGun = game:GetService("ReplicatedStorage").EventName local Buy = script.Parent.BuyButton --Obviously, change this to the location of the button local Gun = "DefaultGun" Buy.MouseButton1Click:Connect(function() PurchaseGun:FireServer(Gun) end) --I am assuming the player uses a GUI to choose the gun type? In that case, you need to add functions for whatever buttons you are using to choose. For example, local RevolverButton = script.Parent.RevolverButton --Change location as needed RevolverButton.MouseButton1Click:Connect(function() Gun = "Revolver" end) --If you want the player to just press the gun button, as in the Player presses "revolver" and it attempts to buy the revolver, local RevolverButton = script.Parent.RevolverButton --Change location as needed RevolverButton.MouseButton1Click:Connect(function() PurchaseGun:FireServer("Revolver") end) --This would get rid of the BuyButton function, but you would need to create one of these for every gun.
Any questions, just ask
line 9 should be
local clonegun = ReplicatedStorage.Guns:FindFirstChild("GunItemName").Value