Character is Not a Valid Member of CFrame Error

I’m still making the Harry Potter Wand. The issue now is that it says that Character is Not a Valid member of CFrame.

-- Server Side

local RepStorage = game:GetService("ReplicatedStorage")
local Event = RepStorage:WaitForChild("AvadaKedavraEvent")
local spell = game.ReplicatedStorage.Spell.Value

local function avadakedavra(hit, plr, orientation)
	local wand = game.StarterPack.Wand
	spell = 0
		-- error area
		local ray = Ray.new(
			plr.Character.Head.CFrame.p,
			(hit.p - plr.Character.Head.CFrame.p).unit * 200)
		local ignore = plr.Character
		-- end error area
		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 = 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

Event.OnServerEvent:Connect(avadakedavra)

-- Client Side

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event = ReplicatedStorage:WaitForChild("AvadaKedavraEvent")

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

local plr = game.Players.LocalPlayer

local orientation = script.Parent.Handle.Orientation

mouse.Button1Down:Connect(function()

event:FireServer(mouse.Hit, plr, orientation)

end)

-- Activation Script

local player = game.Players.LocalPlayer
local spell = game.ReplicatedStorage.Spell

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

The issue is because of how you are firing and receiving the remote events. When a remote event is fired from the client the player is automatically pass as the first argument so there is no need to put it in the arguments however when you are receiving it on the server it must be defined first. To correct this fix your following lines of code:

--Client script:
--change the following line:
event:FireServer(mouse.Hit, plr, orientation)
--to this
event:FireServer(mouse.Hit,orientation)

--Server Side 
--change the following line:
local function avadakedavra(hit, plr, orientation)
--to this
local function avadakedavra(plr,hit, orientation)

Ok, so, it fixed the other error, but now it says that magnitude is not a valid member of CFrame.

try doing this

--server side:
--change this line:
beam.CFrame = CFrame.new(plr.Character.Head.CFrame.p - position).magnitude
--to this:
beam.CFrame = CFrame.new(plr.Character.Head.CFrame.p - position).Position.magnitude

It didn’t work. Why did you close it twice?

Just noticed i edited the reply try that instead and can i ask why are setting the cframe of the beam to the magnitude anyways?

I don’t know why honestly. Now it says that position is not a valid member of CFrame.

do this instead:

beam.CFrame = CFrame.new(plr.Character.Head.CFrame.p - position)

--also can you tell me what the script is suppose to do?

Well, it fires out now, but it fires whenever I click. I don’t need the wand out, and I don’t need to say the spell. Also, it’s an HP wand.

so you want it to only fire when the wand is out and say the spell?

Yes, as shown in the activation script in the first post.

ok on the client put the activated script and client script in one like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("AvadaKedavraEvent")
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local orientation = script.Parent.Handle.Orientation
local spell = game.ReplicatedStorage.Spell
local SpellChatted = false
local VALID_DURATION = 3--this is time in seconds of how the long the spell should be valid after the player types it

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

player.Chatted:Connect(function(msg)
	local msg = msg:lower()
	if msg:match("avada kedavra") then
		SpellChatted = true
		print("Player has typed in the spell.")
		wait(VALID_DURATION)
		SpellChatted = false
	end
end)

change the server side script to this:

--Server side
local RepStorage = game:GetService("ReplicatedStorage")
local Event = RepStorage:WaitForChild("AvadaKedavraEvent")
local spell = game.ReplicatedStorage.Spell.Value
local wand = game.StarterPack.Wand

local function IsWandEquipped(character)
    return character[wand.Name]
end

local function avadakedavra(plr,hit,orientation,spellChatted)
    local character= plr.Character or plr.CharacterAdded:wait()
    if spellChatted and IsWandEquipped(character) then
	    spell = 0
		local ray = Ray.new(
			plr.Character.Head.CFrame.p,
			(hit.p - plr.Character.Head.CFrame.p).unit * 200)
		local ignore = plr.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 = 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)
		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
Event.OnServerEvent:Connect(avadakedavra)
1 Like

Thank you so much! I have been trying to fix this issue for days!

its no problem i am glad to help