Help with RemoteEvents

Im gna be making alot of abilities for my game, how would i go about making the remote events, do i have 1 that i pass everything thru, 1 for every class, 1 for every player or 1 for every ability

Actually, it’s 1 for every script task required. There is no concrete rule to the holistic idea. It could possibly require about more than 1 remote for each ability, for instance.

I definitely would not do a remote event for every skill in your game because that would be very costly for the memory in your game.

I’ve only made one moveset before so my method probably isnt the most efficient, but I use a module script for every set of moves (for e.g lightning, i had three moves and an ultimate and the code for those moves were all inside the module script.

its pretty simple

  1. I fire a remote event everytime a player presses one of the skill keybinds

  2. a server script that receives the remote gets the moveset that the player has.

  3. require the module script and calls the move in the server script

That way I only have to use a single remote event

1 Like

im guessing 1 for every moveset right?

You can do that but I used one for every time a player presses one of the skill keybinds. For example the player has z,x,c,v as their skill 1, 2, 3, ultimate and I have a local script that detects whenever they press one of the keybinds, then fires a single remote I named “movement” which passes through the skill number the player wants to cast. For example the player presses the z key which is skill 1, it would fire “skill one” to the server. The server would then get the move set that the player has then require the module script for the player then cast the skill.

You can take a look at my scripts

local script under startcharacterscripts

local keybinds = {
	[Enum.KeyCode.R] = "Reload",
	[Enum.KeyCode.F] = "Dash",
	[Enum.KeyCode.Z] = "Skill1",
	[Enum.KeyCode.X] = "Skill2",
	[Enum.KeyCode.C] = "Skill3",
	[Enum.KeyCode.V] = "Ultimate",
	[Enum.KeyCode.E] = "PickUp"
}

UserInputService.InputBegan:Connect(function(input, typing)
	if typing then return end
	local char = Player.Character
	local weapon = char:GetAttribute("CurrentGun")
	local movement = keybinds[input.KeyCode]
	
	
	-- Keyboard Inputs
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if movement then
			local mousePos = player:GetMouse()
			print(mousePos.X)
			Remote:FireServer(movement, mousePos.Hit.Position)
		end
    end
end)

Server script under serverscriptservice

local RS = game:GetService("ReplicatedStorage")
local SSS = game:GetService("ServerScriptService")
local SS = game:GetService("ServerStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local PlayerDataHandler = require(SSS.PlayerDataHandler)
local WeaponsModule = require(SS.WeaponStats.ModuleScript)
local PlayerSkillModule = {}

local Remotes = RS.Remotes

local updateHeat = Remotes.updateHeat
local Movement = Remotes.Movement

local Skill1Anim = {}
local Skill2Anim = {}
local Skill3Anim = {}
local UltimateAnim = {}
local SkillStats

local PlayerSkills = {}

local Skill1Debounce = {}
local Skill2Debounce = {}
local Skill3Debounce = {}
local UltimateReady = {}



Movement.OnServerEvent:Connect(function(plr, keypressed, mousePos)
	print(mousePos)
	
	local keybind = PlayerDataHandler:Get(plr, "keybinds")
	local char = plr.Character
	local hum = plr.Character.Humanoid
	PlayerSkills[plr] = PlayerDataHandler:Get(plr, "Skill")
	
	local skill = PlayerSkills[plr]
	
	print(skill)
	
	SkillStats = WeaponsModule.GetStats(PlayerSkills[plr])
	PlayerSkillModule[plr] = require(SS.Skills:FindFirstChild(skill).ModuleScript)
	
	
	if keypressed == "Skill1" and not Skill1Debounce[plr] then
		
		Skill1Debounce[plr] = true
		
		PlayerSkillModule[plr]:MissleLaunch(plr, mousePos)
		
		while Skill1Debounce[plr] do
			task.wait(SkillStats.Skill1CD)
			Skill1Debounce[plr] = false
		end
	end
	
	if keypressed == "Skill2" and not Skill2Debounce[plr] then
		Skill2Debounce[plr] = true
		
		PlayerSkillModule[plr]:Skill2(plr)
		
		
		while Skill2Debounce[plr] do
			task.wait(SkillStats.Skill2CD)
			Skill2Debounce[plr] = false
		end
		
	end
	
	if keypressed == "Skill3" and not Skill3Debounce[plr] then
		Skill3Debounce[plr] = true
		
		PlayerSkillModule[plr]:Skill3(plr)

		while Skill3Debounce[plr] do
			task.wait(SkillStats.Skill3CD)
			Skill3Debounce[plr] = false
		end
		
	end
	
	if keypressed == "Ultimate" then

		
	end
end)

if you have any question please ask I left some things out because my reply would be too long

I use profile service instead of datastore and use the :Get function to get the player’s moveset. You obv dont need to use profile service

yh thats what i woulda did

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