Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make multiple arguments for one RemoteEvent?

I'm trying to make multiple arguments using one RemoteEvent for my shop so exploiters can't exploit RemoteEvents. Here's my script for reference:

game.ReplicatedStorage.ShopService.OnServerEvent:Connect(function(Player, SodaPop,SandWhich,Water)

	if SandWhich then
		local SandWhich = game.ServerStorage.Tools.Consumables["Sand Which"]:Clone()
		SandWhich.Parent = Player.Backpack
		Player.Stats.Cash.Value = Player.Stats.Cash.Value - 8
	end

	if Water then
		local Water = game.ServerStorage.Tools.Consumables["Water"]:Clone()
		Water.Parent = Player.Backpack
		Player.Stats.Cash.Value = Player.Stats.Cash.Value - 4
	end

	if SodaPop then
		local SodaPop = game.ServerStorage.Tools.Consumables["Soda Pop"]:Clone()
		SodaPop.Parent = Player.Backpack
		Player.Stats.Cash.Value = Player.Stats.Cash.Value - 15
	end
end)

In my LocalScript theres 3 variables that say "= true" after them to try make them work so I do game.ReplicatedStorage.ShopService:FireServer(SandWhich) etc. But that doesn't work because either way it gives me the SodaPop. So I need help with an explanation of some sorts. Thanks.

3 comments

0

In the local script try to do game.ReplicatedStorage.ShopService:FireServer(false, true, false)

0

^^^^^^ Doesn't work because I'm trying to fire multiple arguments and I cant to that for each one.

0

Are you trying to make all of them true? I'm a bit confused on what you're trying to do. If so, then do game.ReplicatedStorage.ShopService:FireServer(true, true, true)

2 answers

You should check if the player has enough before awarding them the item. However, i see nothing else wrong with the serverscript, so show the localscript in which you are firing it. Make sure u are firing the values in the correct order and that they have the desired values.

There are some errors First of all u should always use Elseif, Example :

if SandWhich == true then
        local SandWhich = game.ServerStorage.Tools.Consumables["Sand Which"]:Clone()
        SandWhich.Parent = Player.Backpack
        Player.Stats.Cash.Value = Player.Stats.Cash.Value - 8
   

   elseif Water == true then
        local Water = game.ServerStorage.Tools.Consumables["Water"]:Clone()
        Water.Parent = Player.Backpack
        Player.Stats.Cash.Value = Player.Stats.Cash.Value - 4
    

    elseif SodaPop == true then
        local SodaPop = game.ServerStorage.Tools.Consumables["Soda Pop"]:Clone()
        SodaPop.Parent = Player.Backpack
        Player.Stats.Cash.Value = Player.Stats.Cash.Value - 15
    end
end)

Im assuming the person cant buy multiple consumables at once The other thing u should do is actully check if its true because rn ur just checking if the variable exists If this answer helps u please click the answer button to give us both a cool reward

3 comments

0

no, you can do if variable then, that still checks if it's true. On the contrary though you can also do if not variable then to check if it's false

0

oh sorry i didnt know

0

doing "elseif" works the same as multiple if statements.

This discussion is preserved as it was. New answers, comments, and votes are closed.