I probably should have learned this when i first started scripting but
game:GetService("ReplicatedStorage").Remote.OnServerEvent:Connect(function(player)
local function damage(player,amount)
end
local function effect(player,cframe,model,size,speed)
local mdl = model:Clone()
mdl.Parent = game.Workspace
mdl.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
end
local function transparency()
end
local function dodge()
end
local function velocity()
end
end)
So I’m trying to get effects to work
Is there any way i can like pull this off
Like run a remote with the paramaters of effect
I don’t want to have like 40 remotes controlling 40 different things
Alright well, this is possible but can be done alternatively with modules but if you choose to do this way then thats alright. Firstly, I wouldn’t recommend defining all of the functions within the event as that’s just inefficient. Define them outside of the event.
Now, when you fire the event, you should fire another parameter, the func type. This would be something like damage, effect, transparency, etc. Now, all you have to do is check if func type == "". Hypothetically this can be done smarter with first class functions and a table but that’d be a bit too advanced.
Now, because you’ll need to get those parameters from the fired remote, how do we make it so we can have 5 parameters, or just 2? Do we have to write all 5 and just not use them? Luckily, with lua we can simply do … and that’ll store all additional parameters. However, we’ll have to redefine them with something like ``local args = {…}`, I cant remember the reason as to why however it won’t work otherwise.
Now, we can pass those args and all you have to do now is pass the correct function.
local remote = game:GetService("ReplicatedStorage").RemoteHere
remote.OnServerEvent:Connect(function(player, funcType, ...)
local args = {...}
-- func stuff here, not writing for time
effect(player, args)
end)
Inside of the effect function you’d have to split args as right now if you printed all of its entries it’d just print CFrame, model, size, speed (granted you passed them into the remoteEvent)
game:GetService("ReplicatedStorage").Remote.OnServerEvent:Connect(function(player,functype, ...)
if functype == "air" then
local args = {player,cframe,model,size,speed}
effect(player, args)
end
end)
and this for effect
local function effect(player,cframe,model,size,speed)
local mdl = model:Clone()
mdl.Parent = game.Workspace
mdl.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
end
Args is literally represented by the …, it isn’t like kwargs (keyword args) which has key-value pairs. You’ll have to index them individually in the order they were written, or:
local rawArgs = {...}
local args = {
player = rawArgs[1],
cframe = rawArgs[2],
-- etc
}```
Remember that args is simply all of the other parameters that have been passed without being labeled, so it’d just look like any other remoteEvent Firing.
Nothings changed about how we pass them to the server, it’s just how we store them. It’s like putting a bunch of items into a box and then sending it to someone. They don’t know whats in the box unless its labelled, and our … is just the unlabelled stuff.