Shop script not working

So im making a tool shop for my game, but it seems to be not working after a change i made to cost survivals, could anyone help me?

The script

local MainFrame = script.Parent.MainFrame
local ScrollingFrame = MainFrame.ScrollingFrame
local player = game.Players.LocalPlayer
local CloseButton = MainFrame.TextButton

ScrollingFrame.Pistol.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 125 and player.leaderstats.Survivals.Value > 25 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 125
		game.ReplicatedStorage.Pistol:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.SupplyGun.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 85 and player.leaderstats.Survivals.Value > 10 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 300
		game.ReplicatedStorage.CallSupplyDrop:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.M4A1.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 280 and player.leaderstats.Survivals.Value > 45 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 300
		game.ReplicatedStorage.M4A1:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.Ak47.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 280 and player.leaderstats.Survivals.Value > 75 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 300
		game.ReplicatedStorage.Ak47:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.ScarL.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 500 and player.leaderstats.Survivals.Value > 125 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 300
		game.ReplicatedStorage.ScarL:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.StunBaton.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 150 and player.leaderstats.Survivals.Value > 10 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 300
		game.ReplicatedStorage.StunBaton:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.Axe.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 250 and player.leaderstats.Survivals.Value > 50 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 300
		game.ReplicatedStorage.Axe:Clone().Parent = player.Backpack
	end
end)
ScrollingFrame.Eerie.Buy.MouseButton1Click:Connect(function()
	if  player.leaderstats.Coins.Value > 1000 and player.leaderstats.Survivals.Value > 5 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1000
		game.ReplicatedStorage.Eerie:Clone().Parent = player.Backpack
	end
end)

It would be cool if anyone could help me

1 Like

Your script is on the client, therefore when you clone the items on the client they do not replicate to the server.
In order to make it work, you need to create a server script and a remote event. After that, you need to make it so that the client fires the remote event with the name of the weapon.

-- Client Example
local MainFrame = script.Parent.MainFrame
local ScrollingFrame = MainFrame.ScrollingFrame
local player = game.Players.LocalPlayer
local CloseButton = MainFrame.TextButton
local PurchaseEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") -- The path to the remote event, you can name both the variable and the event however you'd like

ScrollingFrame.Pistol.Buy.MouseButton1Click:Connect(function()
	if player.leaderstats.Coins.Value > 125 and player.leaderstats.Survivals.Value > 25 then
		PurchaseEvent:FireServer("Pistol")
	end
end)

Then in the server script you connect a function to when the remote event is fired, do all the appropriate checks and finally clone the weapon into the players inventory

-- Server Example
local PurchaseEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
-- The first argument of OnServerEvent is always the player who fired the remote event
PurchaseEvent.OnServerEvent:Connect(function(player,ItemName)
	if ItemName == "Pistol" then
		if player.leaderstats.Coins.Value > 125 and player.leaderstats.Survivals.Value > 25 then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 125
			game.ReplicatedStorage.Pistol:Clone().Parent = player.Backpack
		end
	end
end)

Also two tips

  1. Put the script in ServerScriptService
  2. Store the weapons in ServerStorage instead of ReplicatedStorage

If the problem still occurs, reply back!

1 Like

Yo this worked, thx! i didnt knew i needed remote events for that!