Dont know how to use one remote event for my scripts

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

  2. What is the issue? Include screenshots / videos if possible!
    I want to use one remote event but idk how to

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    nothing so far
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    I’m making this game that includes weapons and there’s a GUI like a weapon giver GUI and every button has the same Weapon giver script but when I try to fire 2 tools that have the same remote event it fires both and if I do that to the rest it fires all of them anyway to go around this?

--Gui Script 
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.GRemotes.GiveGear1:FireServer()
end)

-- This is the server script im using separate events for it for now but I want to use just one

game.ReplicatedStorage.GRemotes.GiveGear1.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.ZygrainbowPeriastron:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.ZygrainbowPeriastron:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear2.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.WindSword:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.WindSword:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear3.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.WaterSword:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.WaterSword:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear4.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.TyrantPeriastron:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.TyrantPeriastron:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear5.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.TwoSeaterRainbowMagicCarpet:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.TwoSeaterRainbowMagicCarpet:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear6.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.TinyTank:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.TinyTank:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear7.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.TimePeriastron:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.TimePeriastron:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear8.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.TelamonsterTheChaosEdge:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.TelamonsterTheChaosEdge:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear9.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.TPTool:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.TPTool:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear10.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items["Galactic Green Blaster"]:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items["Galactic Green Blaster"]:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear11.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.SnowyGravityCoil:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.SnowyGravityCoil:Clone().Parent = player.Backpack
end)
    game.ReplicatedStorage.GRemotes.GiveGear12.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.Items.SnowShieldAndSword:Clone().Parent = player.StarterGear
    game.ReplicatedStorage.Items.SnowShieldAndSword:Clone().Parent = player.Backpack
end)

1 Like

You can use 1 remote event and set which tool to be cloned via a string. Also make use of variables to abstract a lot of your code and make it more readable.

local repStorage = game:GetService("ReplicatedStorage")
local items = repStorage.Items
local remotesFolder = repStorage.GRemotes
local remote = remotesFolder.GiveGear -- 1 remote event called GiveGear

remote.OnServerEvent:Connect(function(plr, gearName) 
   items[gearName]:Clone().Parent = plr.StarterGear
   items[gearName]:Clone().Parent = plr.Backpack
end)

-- Clientside

local remote = game:GetService("ReplicatedStorage"):WaitForChild("GRemotes").GiveGear

remote:FireServer("Galactic Green Blast") -- Pass in the name of the Tool as an argument.

Also, I recommend implementing checks on the server side so that way your remote event cant be exploited.

wait remote event can still be exploited even with fe? whats wrong with that whats the wrost they can do?

also why :GetService whats wrong with just saying game.ReplicatedStorage?

Well if there are no checks, then the client is able to fire the remote event without a problem. This means that an exploiter could fire your remote event and get access to a tool in perhaps a situation where you don’t want them to. Its a general rule of thumb to never trust the client when it comes to remote events.

For example, lets say you had a remote event to buy a gun and it costs in game money. If you had no checks on the server and there were only checks on the client i.e. in a localscript then an exploiter could just avoid going through the script and fire the remote event directly, giving them direct access to a weapon.

ohh ok i see what you mean now

It means the same thing but :GetService() is just considered cleaner and better practice.

Also in a situation where ReplicatedStorage is, for some reason, not named ReplicatedStorage (as some anti-exploit scripts do as they assign each service a randomly generated name), if you do game.ReplicatedStorage it won’t find Replicated storage, whereas it will still work if you do game:GetService(“ReplicatedStorage”)

Oh ok i see now thx by the way should i live the gui script alone and focus on the server script?

It’s up to you, its you’re project lol.

welll what do i replace the serer script or the gui script which part does that code go in?

Try out the server script to see if it works. Don’t delete your previous work, just comment it out. On the client side, just fire the event with the name of the needed tool as the argument wherever you need to fire an event.

do i replace gearname with the weapon name?

yeah when you’re calling from the client.

If you wanted a TinyTank then you could call: remote:FireServer("TinyTank")

Or if you wanted a Galactic Green Blastic then call remote:FireServer("Galactic Green Blast")

Make sure that the string name matches up with the name of the Tool in replicatedStorage.
As a matter of fact, maybe after you get the script working I would suggest moving your items into server storage and adjusting the code as we don’t particularly want the client to have unrestricted access to them.

This would involve moving the items folder to Server Storage and just changing the items variable to something like game:GetService("ServerStorage").Items

wait shouldnt you define plr? like game:GetService(“Players”).LocalPLayer

When you fire a remote event from the client, it passes the player that fired the remote event as the first argument automatically. Read up further on remote events and their behaviour

I wont be replying further to this thread. Good luck :+1:

before you go why did this happen


Because you’re firing a remote event to the server from the server. Like I said read up on how they work on the article I mentioned and linked for you.

local repStorage = game:GetService("ReplicatedStorage")
local items = repStorage.Items
local remotesFolder = repStorage.GRemotes
local remote = remotesFolder.GiveGear1


remote.OnServerEvent:Connect(function(plr, WindSword)
    items[WindSword]:Clone().Parent = plr.StarterGear
    items[WindSword]:Clone().Parent = plr.Backpack
end)

local remote = game:GetService("ReplicatedStorage"):WaitForChild("GRemotes").GiveGear1

remote:FireServer("WindSword")

Remove the bottom two lines. Use the bottom line in your GUI when you need to call the remote to equip the player with a tool.