Unable to cast double to Vector3

I was transporting part of my local script to a server script in a gun then when I went to test it, an error popped up saying “Unable to cast double to Vector3, line 17”. I’m not sure what the error means or how to fix it, anyone know what it means and how to fix it?

The error is on this script(server script):

gun = script.Parent
fire = gun.Handle:WaitForChild('Fire')

local Glass = {"1565824613"; "1565825075";}
local Metal = {"282954522"; "282954538"; "282954576"; "1565756607"; "1565756818";}
local Grass = {"1565830611"; "1565831129"; "1565831468"; "1565832329";}
local Wood = {"287772625"; "287772674"; "287772718"; "287772829"; "287772902";}
local Concrete = {"287769261"; "287769348"; "287769415"; "287769483"; "287769538";}
local Hits = {"363818432"; "363818488"; "363818567"; "363818611"; "363818653";}
local Whizz = {"342190005"; "342190012"; "342190017"; "342190024";}


game.ReplicatedStorage.Fired.OnServerEvent:Connect(function(damage, range, torsomulti, headmulti, firerate, origin, direction, destination)
	fire:Play()
	gun.Firepart.MuzzleFlash:Emit(10)
	
local raycastResult = workspace:Raycast(origin, direction) -- (17)The error is on this line

	if raycastResult and gun.Ammo.Value > 0 then
		
		local part = script.PartMarker:Clone()
		part.Position = raycastResult.Position
		part.Parent = game.Workspace.Effects.EffectStorage
		part.Anchored = true
		part.Material = raycastResult.Instance.Material
		
			local AttachmentA = Instance.new("Attachment")
			AttachmentA.WorldPosition = origin
			AttachmentA.Name = "AttachmentA"
			AttachmentA.Parent = gun.Firepart

			local AttachmentB = Instance.new("Attachment")
			AttachmentB.WorldPosition = destination
			AttachmentB.Name = "AttachmentB"
			AttachmentB.Parent = part
				
			local beam = gun.Firepart.Beam:Clone()
			beam.Attachment0 = AttachmentB
			beam.Attachment1 = AttachmentA
			beam.Parent = game.Workspace

	



	local hum = raycastResult.Instance.Parent:FindFirstChild('Humanoid')
	if hum then
		if raycastResult.Instance.Name == 'Torso' then
			hum:TakeDamage(damage*torsomulti)
		elseif raycastResult.Instance.Name == 'Head' then
			hum:TakeDamage(damage*headmulti)
		else
			hum:TakeDamage(damage)
		end
		local blood	= gun.Handle.Blood:Clone()
		blood.Parent = raycastResult.Instance
		local S = Instance.new("Sound")
		S.EmitterSize = 20
		S.MaxDistance = 40
		S.SoundId = "rbxassetid://".. Hits[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = hum
		S.PlayOnRemove = true
		S:Destroy()
		blood:Emit(5)
	elseif raycastResult.Instance.Material == Enum.Material.Glass then
		part.Glass:Emit(5)
		part.Glass1:Emit(5)
		part.Glass2:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Glass[math.random(1, 2)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Metal then
		part.Metal:Emit(5)
		part.Metal1:Emit(5)
		part.Metal2:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Metal[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.DiamondPlate then
		part.Metal:Emit(5)
		part.Metal1:Emit(5)
		part.Metal2:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Metal[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.CorrodedMetal then
		part.Metal:Emit(5)
		part.Metal1:Emit(5)
		part.Metal2:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Metal[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Concrete then
		part.Rock:Emit(5)
		part.Rock1:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Concrete[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Slate then
		part.Rock:Emit(5)
		part.Rock1:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Concrete[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Marble then
		part.Rock:Emit(5)
		part.Rock1:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Concrete[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Granite then
		part.Rock:Emit(5)
		part.Rock1:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Concrete[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Wood then
		part.Wood:Emit(5)
		part.Wood1:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Wood[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.WoodPlanks then
		part.Wood:Emit(5)
		part.Wood1:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Wood[math.random(1, 5)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()	
	elseif raycastResult.Instance.Material == Enum.Material.Grass then
		part.Dirt:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Grass[math.random(1, 4)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	elseif raycastResult.Instance.Material == Enum.Material.Sand then
		part.Dirt:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Grass[math.random(1, 4)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
	else 			
		part.Dirt:Emit(5)
		local S = Instance.new("Sound")
		S.SoundId = "rbxassetid://".. Whizz[math.random(1, 4)]
		S.PlaybackSpeed = math.random(30,55)/40
		S.Volume = 2
		S.Parent = part
		S.PlayOnRemove = true
		S:Destroy()
		end
		part:Destroy()
	end
end)
1 Like

This means that you’ve provided a number when you should have provided a Vector3.

This is probably because you forgot to set the first parameter to plr, which is an argument passed to OnServerEvent automatically. To fix this, add a “plr” parameter before the damage parameter.

Not taking the plr parameter into account means that damage is set to the player object, and range is set to whatever you wanted to pass as damage.

4 Likes

How exactly do I do that? I added it in and it still says the same error. Unless I’m doing it wrong. I added it in to when it fires the event and when it receives it. I’m sure this works but I dont think I’m doing it right.

2 Likes

No need to add it into where it fires the event. Only add it to the part that receives the event.

4 Likes