How to make my variable work inside function w/ raycast

Simple question I am in the process of modifying a script of a roblox tool from the olden times. But i need the spawnpos variable to be detected in my raycast and it says it’s “unknown global variable”. How do I make it work? I could just use a string value but I get the feeling that it may be redundant. Is there a simpler way ? (sorry if this has been asked before)

Here is the important part of the script:

function fire(v)

	

	

	local missile = Instance.new("Part")
	

        
	spawnPos = vCharacter.PrimaryPart.Position + Vector3.new(8, 0, 0)
	
	local ray_for_tween = workspace:Raycast(spawnpos, Tool.Parent.Torso.LookVector * 10000)

thanks in advance

In the raycast, “spawnpos”, the p should be capitalized like the variable “spawnPos” is. Also, you can make the variable a local variable since its only being used inside the function (I think)

1 Like

ohhh yea i just made a silly mistake. thank you