#My script for my gun gets an error when I make the local direction variable.
1 messages · Page 1 of 1 (latest)
the big one is the server script where the error happens and the small one is the client script I don't think there is any error there but maybe
** You are now Level 5! **
Which line gives the error?
the local direction
local direction = (mousepos - origin).Unit * dist_mult
in the server script
^^
Okay sk
.unit returns a vector3
But you do multi * vector3
Mabey try vector3.new(1,1,multi) * (balh).unit
Cant multiply a number with vector3
So turn number into vector3
I will try
also what is balh?
sorry I don't know much about these stuff but what is ib?
local tool = script.Parent
local pointpart = tool:WaitForChild("Handle"):WaitForChild("Point")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local firegun = tool:WaitForChild("firegun")
tool.Activated:Connect(function()
firegun:FireServer(pointpart.Position, mouse.Hit.Position)
end) put this in the tool in a local script
I did
local scriot
yeah
script
local tool = script.Parent
local firegun = tool:WaitForChild("firegun")
local dist_mult = 50
local excludeparts = {}
local function visualizeray(origin, direction)
local length = direction.Magnitude
local midpoint = origin + direction * 0.5
local newpart = Instance.new("Part")
newpart.Anchored = true
newpart.CanCollide = false
newpart.Material = Enum.Material.Neon
newpart.Color = Color3.fromRGB(255, 148, 61)
newpart.Size = Vector3.new(0.1, 0.1, length)
newpart.CFrame = CFrame.new(midpoint, origin + direction)
newpart.Parent = workspace
game.Debris:AddItem(newpart, 0.5)
end
firegun.OnServerEvent:Connect(function(player, origin, mousepos)
local direction = (mousepos - origin).Unit * dist_mult
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = excludeparts
raycastparams.FilterType = Enum.RaycastFilterType.Exclude
local rayresult = workspace:Raycast(origin, direction, raycastparams)
if rayresult then
print("Result found!", rayresult)
visualizeray(origin, direction)
rayresult.Instance.Color = Color3.fromRGB(0, 255, 217) -- Changes hit part color
else
print("Result not found!")
visualizeray(origin, direction)
end
end)
this one too
in the tool loca script
did it work?
is in a server script but I'm sure that is right
if is in a local script it will not affect the server
what is ib?
did it work
nope
The error you're seeing —
attempt to perform arithmetic (sub) on Vector3 and Instance — is happening because you're trying to subtract a Vector3 (a position) from an Instance (an object like a Part), which isn't valid.
Let’s look at the relevant part of your server script:
firegun.OnServerEvent:Connect(function(player, origin, mousepos)
local direction = (mousepos - origin).Unit * dist_mult
You're expecting both origin and mousepos to be Vector3 values (positions), but one of them isn't — likely origin.
From your local/client script, this is the part where you call FireServer:
firegun:FireServer(pointpart.Parent, mouse.Hit.Position)
You’re passing:
pointpart.Parent (which is a Model or Tool, i.e., an Instance) as origin
mouse.Hit.Position (which is a Vector3) as mousepos
You need to send a Vector3 position instead of pointpart.Parent.
try that
that is the problem that i see
you understand
thank you I was wrong about the pointpart small script