Spell System Bug

Hey, I’m wokring on a game and I’m struggling to make the main wand system and I need it to be really smooth and stuff, and like the video I’ve referenced to.

Current Code -

-- # Casting System Main
WandModule.Cast = function(NameOfSpell, Character, Target)
	-- # Play Animations Here
	local Animation = Instance.new('Animation')
	Animation.AnimationId = 'rbxassetid://10958064518'
	
	Character.Humanoid:LoadAnimation(Animation):Play()
	-- # Fire To Server
	game.ReplicatedStorage.Events.SpellEvent:FireServer(NameOfSpell, Target)
	print(NameOfSpell .. ' Casting')
end

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Storage = ReplicatedStorage.Storage
local Events = ReplicatedStorage.Events
local Modules = ReplicatedStorage.Modules

-- # Main
ReplicatedStorage.Events.SpellEvent.OnServerEvent:Connect(function(Player, Spell, Target)
	if Player and Spell and Target then
		local projectile 
		if not game.ReplicatedStorage.Modules.WandModule.Projectiles:FindFirstChild(Spell) then
			projectile = game.ReplicatedStorage.Modules.WandModule.Projectiles.Main:Clone()
			local SpellInfo = require(game.ReplicatedStorage.Modules.WandModule.SpellInfo)
			
			--for _, v in pairs(projectile:GetDescendants()) do

			--	if v:IsA("ParticleEmitter") or v:IsA("PointLight") then
			--		v.Color = SpellInfo.Colors[Spell].Color
			--	end
			--end
		else
			projectile = game.ReplicatedStorage.Modules.WandModule.Projectiles:FindFirstChild(Spell):Clone()
		end
		
		projectile.Parent = Player.Character
		projectile.Position = Player.Character.RightHand.Position
		projectile.Anchored = true
		projectile.CanCollide = false
		
		game.ReplicatedStorage.Events.SpellEvent:FireClient(Player, Player, projectile, Target)
	end
end)
-- # Spell Event (Client, fired from the server to client)
ReplicatedStorage.Events.SpellEvent.OnClientEvent:Connect(function(Player, Spell, Target)
	if Player and Spell and Target then

		local randomVec = {Vector3.new(0,0,6), Vector3.new(6,0,0), Vector3.new(0,1,0)}

		local P1 = Player.Character.RightHand
		local P2 = Instance.new('Part', workspace)
		P2.Anchored = true
		P2.Transparency = 1
		P2.Position = Target.Position
		local hasHit = false
		local moveVector = randomVec[math.random(1, #randomVec)]
		
		local bodyVelocity = Instance.new('BodyVelocity', Spell)
		bodyVelocity.MaxForce =Vector3.new(10000, 10000, 10000)
		bodyVelocity.Velocity = (Spell.Position - Target.Position).Unit *55
		while true do
			wait()
			if hasHit == false then
				bodyVelocity.Velocity = (Spell.Position - Target.Position).Unit *25
				print("hi!!")
			else
				hasHit = false
				Spell:Destroy()
				return
			end
		end
		
		Spell.Touched:Connect(function(h)
				if hasHit == false and h.Parent ~= Player.Character then
					hasHit = true

					for _, v in pairs(Spell:GetDescendants()) do
						if v:IsA("ParticleEmitter") or v:IsA("PointLight") then
							v.Enabled = false
						end
					end
					
					local hitEffect = game.ReplicatedStorage.Modules.WandModule.Projectiles.Hit:Clone()
					hitEffect.Position = Spell.Position
					hitEffect.Parent = Spell
					hitEffect.Anchored = true
					task.delay(1,function()
						hitEffect:Destroy()
					end)

					task.delay(1.5,function()
						Spell:Destroy()
					end)
					if h.Parent:FindFirstChild('Humanoid') then
						h.Parent:FindFirstChild('Humanoid'):TakeDamage(15)
					end
				end
			end)
	end
end)

I’ve tried lerp, and a lot of other stuff but still not what I want it to be.

(0:49) for the casting reference I’m wanting.

Basically I just need it to be smooth and angle it the way that it is, which I’m mainly struggling with.

Can you post a video of the issue you are seeing when using this script? This will really help determine what you mean by “smooth”.

2 Likes

lol @collector has a wizard hat and the glitch is about a spell system

It doesn’t even work in the first place, (or any movement at all.).