Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make a spell selection system?

So I'm making a game with skills and I've been trying to make some kind of skill selection system so that you can only use selected skills.

I was thinking that I could disable the skill scripts for one player using a localscript, however I quickly realized I would need a normal script for that. But I can't think of anything that would be easy to make and that would not require a new BindableEvent for every skill.

Any ideas?

(Sorry for not being able to show my code, in school rn)

2 answers

You would have to use a normal script that repeatedly checks if to enable and disable

You mean like:

local enabledSkills = {
	"Cooking",
	"Eating",
	"Cats",
}

local function CanUseSkill(skillName)
	return table.find(enabledSkills, skillName)
end

CanUseSkill("Cooking") -- 1 (Table.find returns index from value if it's found in the table)
CanUseSkill("WideSteal") -- nil (If it's not found then table.find will return nil)


If CanUseSkill("Cooking") then
	print(true)
end
--> true

Basically, table.find in this case, checks if value with specific value is in the table, if it is then it will return the index of the value in that table, otherwise it will return nil so if the skill "Cooking" was found, it returned 1 as it is the index of the skill in the table while "WideSteal" is not in the table so the table.find returned nil. Means you can't do If CanUseSkill("Cooking") == true then but you can do If CanUseSkill("Cooking") == nil then (check if it is not in the table) or If CanUseSkill("Cooking") then (check if it is in the table)

You could also use pairs loop for that, it could have some cons in specific situations.

Here is roblox documentation about tables where it explains table.find.

2 comments

0

Thanks a lot! That will probably work, however how would I then go about disabling the localscripts for a specific player? My localscripts are in StarterPlayerScripts and is it even possible to access them? I would need the playe to do that too... But I guess it could work with a remoteevent?

0

Of course you could, you can also do: yourPlayer.PlayerScripts.YourScript.Disabled = true

This discussion is preserved as it was. New answers, comments, and votes are closed.