Shop gives player an item and the amount they get = the amount of players in the server?

If the title was confusing, here’s me explaining it.

The player should get 1 of that item every time they buy it.

Instead, if there is like 14 players in the server, they get 14 of it.

The amount they get depends on the players in server.

My suspicion is that the :FireServer is the problem, and I need to change that but I don’t know how.
Heres the scrip.t

maingui = script.Parent.Parent.Parent

rs = game:GetService("ReplicatedStorage")

display = maingui.Display
main = maingui.Main

button = script.Parent
plr = game.Players.LocalPlayer

-- the annoying part!!!!

ak47 = main.AK47
ak47script = ak47.LocalScript
ak47bought = ak47.Bought

bazooka = main.Bazooka
bazookascript = bazooka.LocalScript
bazookabought = bazooka.Bought

minigun = main.Mingun
minigunscript = minigun.LocalScript
minigunbought = minigun.Bought

slayer = main.FriendSlayer
slayerscript = slayer.LocalScript
slayerbought = slayer.Bought

raigtrust = main.RaigtrustBlade
raigscript = raigtrust.LocalScript
raigbought = raigtrust.Bought

coil = main.RaigCoil
coilscript = coil.LocalScript
coilbought = coil.Bought

dark = main.DarkCoil
darkscript = dark.LocalScript
darkbought = dark.Bought

--find tools in rs

weaponfolder = rs.Weapons

ak47tool = weaponfolder["AK-47"]
bazookatool = weaponfolder.Bazooka
miniguntool = weaponfolder.Minigun
slayertool = weaponfolder.FriendSlayer
raigtool = weaponfolder.RaigtrustBlade
coiltool = weaponfolder.RaigCoil
darktool = weaponfolder.DarkCoil

-- events

eventfolder = rs.WeaponEvents

akevent = eventfolder.AKEvent
bazookaevent = eventfolder.BazookaEvent
minigunevent = eventfolder.MinigunEvent
slayerevent = eventfolder.SlayerEvent
bladeevent = eventfolder.BladeEvent
coilevent = eventfolder.CoilEvent
darkevent = eventfolder.DarkEvent

button.MouseButton1Click:Connect(function()

	local price = button.Price
	local item = button.ItemVal
	
	print(price.Value)
	
	local plrstats = plr:FindFirstChild("leaderstats")
	local raigamount = plrstats:FindFirstChild("RAIG")
	
	if item.Value == 1 and raigamount.Value >= price.Value then -- ak 47
		
		print("bought ak 47")
		
		raigamount.Value -= price.Value + 1
		
		price.Value = 0
		
		ak47script.Enabled = false
		ak47bought.Visible = true
		
		akevent:FireServer()
		
	elseif item.Value == 2 and raigamount.Value >= price.Value then -- bazooka
		
		print("bought bazooka")

		raigamount.Value -= price.Value + 1

		price.Value = 0

		bazookascript.Enabled = false
		bazookabought.Visible = true
		
		bazookaevent:FireServer()
		
	elseif item.Value == 3 and raigamount.Value >= price.Value then -- minigun yayayay

		print("bought minigun")

		raigamount.Value -= price.Value + 1

		price.Value = 0

		minigunscript.Enabled = false
		minigunbought.Visible = true
		
		minigunevent:FireServer()
		
	elseif item.Value == 4 and raigamount.Value >= price.Value then -- friend slayer (so original)

		print("bought friend slayer (SLAY THEM ALL!!!)")

		raigamount.Value -= price.Value + 1

		price.Value = 0

		slayerscript.Enabled = false
		slayerbought.Visible = true
		
		slayerevent:FireServer()
		
	elseif item.Value == 5 and raigamount.Value >= price.Value then -- raigtrust blade

		print("bought raigtrust blade")

		raigamount.Value -= price.Value + 1

		price.Value = 0

		raigscript.Enabled = false
		raigbought.Visible = true
		
		bladeevent:FireServer()
		
	elseif item.Value == 6 and raigamount.Value >= price.Value then -- raig coil (NOT SPEED COIL I SWEAR)

		print("bought raig coil")

		raigamount.Value -= price.Value + 1

		price.Value = 0

		coilscript.Enabled = false
		coilbought.Visible = true
		
		coilevent:FireServer()
		
	elseif item.Value == 7 and raigamount.Value >= price.Value then -- dark coil I SWEAR IT MAY SEEM LIKE GRAVITY COIL BUT IT ISNT!!

		print("bought dark coil")

		raigamount.Value -= price.Value + 1

		price.Value = 0

		darkscript.Enabled = false
		darkbought.Visible = true
		
		darkevent:FireServer()
		
	elseif item.Value == 0 then

		print("bro tried to buy air :skull:")
		
	end
end)
1 Like

You’d have to show the server code to determine the problem. The events just give the server a message that the player attempted to purchase an item, and then the server checks and lets them buy or not buy it.

Here

rs = game:GetService("ReplicatedStorage")

-- events

eventfolder = rs.WeaponEvents

akevent = eventfolder.AKEvent
bazookaevent = eventfolder.BazookaEvent
minigunevent = eventfolder.MinigunEvent
slayerevent = eventfolder.SlayerEvent
bladeevent = eventfolder.BladeEvent
coilevent = eventfolder.CoilEvent
darkevent = eventfolder.DarkEvent

-- weapons

weaponfolder = rs.Weapons

ak47tool = weaponfolder["AK-47"]
bazookatool = weaponfolder.Bazooka
miniguntool = weaponfolder.Minigun
slayertool = weaponfolder.FriendSlayer
raigtool = weaponfolder.RaigtrustBlade
coiltool = weaponfolder.RaigCoil
darktool = weaponfolder.DarkCoil

akevent.OnServerEvent:Connect(function(plr)
	
	ak47tool:Clone().Parent = plr.StarterGear
	ak47tool:Clone().Parent = plr.Backpack
	
end)

bazookaevent.OnServerEvent:Connect(function(plr)

	bazookatool:Clone().Parent = plr.StarterGear
	bazookatool:Clone().Parent = plr.Backpack

end)

minigunevent.OnServerEvent:Connect(function(plr)

	miniguntool:Clone().Parent = plr.StarterGear
	miniguntool:Clone().Parent = plr.Backpack

end)

slayerevent.OnServerEvent:Connect(function(plr)

	slayertool:Clone().Parent = plr.StarterGear
	slayertool:Clone().Parent = plr.Backpack

end)

bladeevent.OnServerEvent:Connect(function(plr)

	raigtool:Clone().Parent = plr.StarterGear
	raigtool:Clone().Parent = plr.Backpack

end)

coilevent.OnServerEvent:Connect(function(plr)

	coiltool:Clone().Parent = plr.StarterGear
	coiltool:Clone().Parent = plr.Backpack

end)

darkevent.OnServerEvent:Connect(function(plr)

	darktool:Clone().Parent = plr.StarterGear
	darktool:Clone().Parent = plr.Backpack

end)

ayyy raigforce reference lmao

anyways this mostly relies with the remotes themselves

can tell you is to change all the remotes into one remote that from client will get the weapon id / weapon name.

the issue here might be with item.Value but idk personally. oh also you do raigamount.Value which is the leaderstat value meaning it probably loops like crazy while thinking you have enough amount of raig

also try to debug your code with more prints

and also THATS IT IM HEADING STRAIGHT FOR THE CORE

You can use the Players service to find the amount of players in the server, and then use that number to create that system.

local Players = game:GetService("Players")
print(#Players:GetPlayers())
-- '#' will return a number, otherwise, it will return a table containing every player in the server

You can learn more about the :GetPlayers() method here:

thats not what bro wanted :skull: he wanted a fix for items multiplying once remote was called

Your problem is a bit weird and this shouldn’t happen unless you spam the button object. Try to debug the code with print when you fire the event.

Something like to check if the plr argument is multiple and collects all players (I don’t think so to be honest)

print(plr.Name.. " bought the 'tool')

Honestly I think I need to change it to :FireClient() but I can’t do that in a local script. The reason I think that is I had another post about remote events and someone said that :FireServer() sends information from a client to server.

:FireServer() is the correct way to send data from client to server
:FireClient() is used to send data from server to client

Everything looks correct with how the event is handled, try adding a debounce to prevent the function from being fired multiple times in a short time-period

I just tried that, nothing changed.

Really not sure then. Just wanted to add as a suggestion that any purchase checks should be handled by the Server. If a hacker wanted to they could just spam those :FireServer() events to get the items and the Server would just give it to them.

since now i have more knowledge on remote events and bindable events and such, im going to try using that to remake or fix this bug (sorry for bumping just wanted to finish this post)

i probably needed to use bindable events instead of remote events basically

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.