Magic Wand Spell: No Errors [HELP NEEDED]

As a side project in ROBLOX, I am making an HP wand. However, it won’t work. It just won’t work. There are no errors. It won’t create the spell.

Server:

local RepStorage = game:GetService("ReplicatedStorage")
local Event = RepStorage:WaitForChild("AvadaKedavraEvent")

local function avadakedavra(plr, hit)
	local wand = game.StarterPack.Wand
	if _G.spell == 1 then
		_G.spell = 0
		local ray = Ray.new(
			plr.Character.Head.CFrame.p,
			(hit.p - plr.Character.Head.CFrame.p).unit * 200)
		local ignore = game.Players.LocalPlayer.Character
		local part, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
		local hit, position, normal = workspace:FindPartOnRay(ray, ignore)
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Lime green")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.5
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
		beam.Orientation = script.Parent.Handle.Orientation
		beam.Shape = Enum.PartType.Block
		beam.Size = Vector3.new(1, 1, 1)
		local distance = (plr.Character.Head.CFrame.p - position).magnitude
		print(distance)
		beam.CFrame = CFrame.new(plr.Character.Head.CFrame.p - position).magnitude
		local start = plr.Character.Head.CFrame
		for i = 1, 10 do
			beam.CFrame = start:lerp(CFrame.new(position), i/10)
			wait()
		end
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
			
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
			
			if humanoid then
				humanoid.Health = humanoid.Health - 110
			end
		end
	end
end

Client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("AvadaKedavraEvent")

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
    event:FireServer(mouse.Hit)
end)

Activation (LocalScript in Wand):

local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)
	local msg = msg:lower()
	if msg:match("avada kedavra") then
		_G.spell = 1
		print("Player has typed in the spell.")
	end
end)

Could someone help me on this?

2 Likes

So, does it print the distance?

No, it does not print out the distance.

Did you forget

Event.OnServerEvent:Connect(avadakedavra);
5 Likes

Okay, mind has been warped. I totally forgot about that.

  1. It appears that you’re relying on _G to replicate between the client and the server. It doesn’t do this. _G is simply a variable that references the same table across every script on the same machine. Instead, pass what spell the user has cast through the RemoteEvent you fire.

  2. You are not doing anything with the avadakedavra function. Perhaps connect it to Event? Event.OnServerEvent:Connect(avadakedavra).

3 Likes

I tried it. It’s still not working.

So, I actually script HP wands for fun and happen to have a free system you can check out.

Also the game is open to test.