Hey devforum, this most may be a long one as it answers some questions that I have regarding my system that I am making.
I am currently making a spell system that allows you to type a spell in chat and when you click on a player, the spell effects will appear on the character, although I’ve came into a minor issue when doing this.
- Would it be easier for me to create module scripts for each spell, instead of a big module / script?
- Retrieving a click from a player, I have made a system although I believe it’s not efficient for this use.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
-- KEY BINDS --
uis.InputBegan:Connect(function(key,IsTyping)
if not IsTyping then
if key.KeyCode == Enum.KeyCode.G then -- PAIN INFLICTION
local Model = mouse.Target:FindFirstAncestorOfClass("Model")
if Model then
local ThePlayer = game.Players:GetPlayerFromCharacter(Model)
game.ReplicatedStorage.Events.SpellEvent.KeybindEvent:FireServer(player,ThePlayer,"pain")
end
end
end
end)
uis.InputBegan:Connect(function(key,IsTyping)
if not IsTyping then
if key.KeyCode == Enum.KeyCode.C then -- PUSH PLAYER
local Model = mouse.Target:FindFirstAncestorOfClass("Model")
if Model then
local ThePlayer = game.Players:GetPlayerFromCharacter(Model)
game.ReplicatedStorage.Events.SpellEvent.KeybindEvent:FireServer(player,ThePlayer,"push")
end
end
end
end)
uis.InputBegan:Connect(function(key,IsTyping)
if not IsTyping then
if key.KeyCode == Enum.KeyCode.K then -- BREAK BONES
local Model = mouse.Target:FindFirstAncestorOfClass("Model")
if Model then
local ThePlayer = game.Players:GetPlayerFromCharacter(Model)
game.ReplicatedStorage.Events.SpellEvent.KeybindEvent:FireServer(player,ThePlayer,"breakbone")
end
end
end
end)
-- SPELLS --
local Spells = {"Incendia","Motus","incendia","motus","ossox","Ossox","Phasmatos morsinus pyrox allum","phasmatos morsinus pyrox allum","Phasmatos incendia circulum","phasmatos incenda circulum"}
uis.InputBegan:Connect(function(key,IsTyping)
if not IsTyping then
if game.ReplicatedStorage.Events.SpellEvent.SpellName.Value ~= "" or nil then
if key.UserInputType == Enum.UserInputType.MouseButton1 then
local Model = mouse.Target:FindFirstAncestorOfClass("Model")
if Model then
local ThePlayer = game.Players:GetPlayerFromCharacter(Model)
if game.ReplicatedStorage.Events.SpellEvent.SpellName.Value == Spells then
game.ReplicatedStorage.Events.SpellEvent:FireServer(player,ThePlayer,game.ReplicatedStorage.Events.SpellEvent.SpellName.Value)
end
end
end
end
end
end)
local camera = game.Workspace.CurrentCamera
game.ReplicatedStorage.Events.RagdollMain.OnClientEvent:Connect(function(Type, target)
if Type == "Ragdoll" then
local targetcharacter = game.Workspace:FindFirstChild(target)
local humanoid = targetcharacter.Humanoid
camera.CameraSubject = targetcharacter.Head
humanoid:ChangeState("Physics")
elseif Type == "Unragdoll" then
local targetcharacter = game.Workspace:FindFirstChild(target)
local humanoid = targetcharacter.Humanoid
camera.CameraSubject = targetcharacter.Humanoid
humanoid:ChangeState("Ragdoll")
end
end)
As seen above, that is a client-sided script that controls if a player clicks on the other player, is there a way for me to improve this at all, and as for that system above does not work with my current system. (Not actually performing the spell.)
Server
local painModule = require(game.ReplicatedStorage.SpellModules.PainInfliction)
local Spells = {"Incendia","Motus","incendia","motus","ossox","Ossox","Phasmatos morsinus pyrox allum","phasmatos morsinus pyrox allum","Phasmatos incendia circulum","phasmatos incenda circulum"}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Character = Instance.new("StringValue",leaderstats)
Character.Name = "Character"
player.Chatted:Connect(function(message)
for _, spell in pairs(Spells) do
if message == spell then
game.ReplicatedStorage.Events.SpellEvent.SpellName.Value = message
print(message)
end
end
end)
end)
game.ReplicatedStorage.Events.SpellEvent.OnServerEvent:Connect(function(caster, target, spell)
if spell == "Motus" or spell == "motus" then
local RagdollModule = require(game.ReplicatedStorage.Ragdoll)
local TargetCharacter = game.Players:FindFirstChild(target).Character
local Humanoid = TargetCharacter.Humanoid
if Humanoid then
RagdollModule:Ragdoll(game.Players:FindFirstChild(target),TargetCharacter)
wait(2)
RagdollModule:Ragdoll(game.Players:FindFirstChild(target),TargetCharacter,Humanoid)
end
end
if spell == "Phasmatos morsinus pyrox allum" or spell == "Pain" then
local damage = 0
damage = 2
print(damage)
local TargetCharacter = game.Workspace:FindFirstChild(target)
local Humanoid = target.Character.Humanoid
local Animation = game.ReplicatedStorage:WaitForChild("GameCore"):WaitForChild("Witches"):WaitForChild("Animations").MassPain
if TargetCharacter and Humanoid then
Humanoid:LoadAnimation(Animation)
caster.Character.Humanoid.Humanoid:LoadAnimation(game.ReplicatedStorage.GameCore.Witches.Animations.PoenaDolorisCasted)
repeat wait(1)
Humanoid:TakeDamage(damage)
if Animation.IsCompleted then
break
end
until Animation.IsCompleted
end
end
end)
And, how would I go about scripting the systems, I have a rough idea but I’m currently stuck, any ideas & suggestions will be counted and appreciated.
Thank you.