Spell System Advice

Hey guys!

I plan on making a game where you use can use spells for combat or passive purposes. The issue here is that I’ve tried and failed! All of the magic systems I’ve made in the past followed this very simple pattern in order for a spell to be casted:

Player sends spell name in chat → Get mouse position from client → Run the corresponding spell on the server, which would handle all of the effects & damage, etc.

This works, but the delay is very undesirable & other games handle this much better, in a way I cannot seem to figure out. What I (BELIEVE) they do, is:

Player activates magic in some way → they render the magic on their client to disguise the input lag → send the server a request to fire all other clients and make them render the magic

This would 100% work & I know how to handle this, HOWEVER if someone joined the game in the middle of a large spell, they wouldn’t see anything because the event never fired for them. Does anyone know how I could fix this issue, besides rendering the spell on the server because it’s quite laggy depending on the servers ping & the ping of the player who fired the spell. (I do not mind that the damage would be laggy, there isn’t really any fixing that!)

1 Like

How are u handling the effects on the client

As you said, you’re gonna want to do the rendering and special effects on the client and the damage dealing on the server. To achieve this create two tables holding all the spells, one for the client to render and the other to be handled on the server.

When you fire the remote, you should pass the information from the client spell to be copied into the server’s spell table. Then when a player joins, you can do something like this:

local serverSpells = {}

game.Players.PlayerAdded:Connect(function(player)
	for i,spellInfo in serverSpells do
		RenderSpell:FireClient(player,spellInfo)
	end
end)

Since the ServerSpells table will already exist before the player joins, you can just loop through the contents of it and render them each to the client.

1 Like

The spell firing when you say it in chat would make it almost impossible to actually aim at people, but I guess this isn’t game design support.

Anyways, I would reccomend chopping up the longer spells into multiple events. This way, even if you don’t recieve the first event, you can still get the others.

yes i do have this system set up in my magic game, for things that would stay in the server for like a minute or longer i run that on the server and for things that go away (like explosion VFX), it would go away in like 5 seconds so you shouldnt be worried if a player just joined because hed need like atleast 20 seconds to even load in the game
you can still do client replication and do them when a player joins, like add it to a table then run it on join