Recently I’ve been trying to make a system that is focused around a Wand where you can cast different spells that are chosen and executed by the player to affect others. How I would like this to work is that the player is given a wand as a tool and when they equip the tool a Gui appears with a list of spells. After selecting the spell it can be cast by clicking where they want it to go.
So far I’ve managed to make the tool with the Gui and when the spell is clicked a String Value inside the player changes to what spell they clicked on.
I have also worked out Ray Casting and creating a bolt to come out the end of the wand when fired. I’ve gotten to the stage that when the ray hits it can do something but am still confused to how to make it do what the selected spell does.
When I have searched this before the things I have found Are: Module Scripts, Dictionaries, Functions, Parameters/Arguments and some examples I looked at included Remote Functions and Events. I am familiar with some of these such as Remote Events and normal Functions but the one thing that confuses me is putting parameters into them.
Update: Thanks everyone for the help Solved by kylepo99. For those wondering I put the top part of the script inside of a module script and the other part inside the firing script where it then detects the humanoid.
I tried that but it ended up with a bunch of else if statements that caused a big performance problem and it took awhile for the server the respond because it has to be done with remote events to affect other players.
When a the spell is clicked on at the Gui it fires a remote event to actually change the value on the player otherwise it doesn’t actually change, I think it has something to do with Filtering Enabled.
The LocalScript which gets the Hit.p from the mouse (the position that the mouse pointed to) should fire a RemoteEvent onto a server script with the following parameters:
The position the mouse hit
The currently active spell
From here the server could take over and set a Vector3Value to the position the mouse hit, perhaps name it the Player’s name to identify who clicked there. From there, create a series of scripts in ServerScriptService each named what each spell is named. Once they’re created, set the “Disabled” value in properties to true. When the server gets the event from the RemoteEvent, simply find the script with the same name as the spell name it received, and set “disabled” to false so that the script runs.
Not sure whether this is entirely fool proof or the best option, but it would certainly improve runtime if you configure it correctly.
local spells = {}
spells["Spell"] = function(arg,second_arg)
-- do spell things
end
local test = "Spell" -- Spell name
local cast_spell = spells[test]("arg1","arg2")