So I was just passing my mouse position and my shoopart onto my clientside bullet, but this error keeps on repeating and I dont know why. Can anyone please help me with this?
Server:
bullet.OnServerEvent:Connect(function(player, mospos, startbul)-- the mouse position and shootpart or start of bullet local origin = startbul.Position local direction = ( mospos -origin).Unit local params = RaycastParams.new() params.FilterDescendantsInstances = {script.Parent, script.Parent.Parent} params.FilterType = Enum.RaycastFilterType.Blacklist params.IgnoreWater = true local result = workspace:Raycast(origin, direction*200, params) if result then local hum = result.Instance.Parent:FindFirstChild("Humanoid") if hum then hum:TakeDamage(30) end end for i,v in pairs(game:GetService("Players"):GetPlayers()) do bullet:FireClient(v, mospos, startbul) end end)
Client:
bullets.OnClientEvent:Connect(function(Players, mousepos, startofbullet) local bullet_clone = clientbullet:Clone() local params = RaycastParams.new() params.FilterDescendantsInstances = {script.Parent.Parent,game.Workspace:WaitForChild("laserbulletsfolder")} params.FilterType = Enum.RaycastFilterType.Blacklist laser.lasersound:Play() local origin = startofbullet local direction = (mousepos - origin).Unit -- the error shows here local result = workspace:Raycast(origin, direction*200, params) if result then print("Client Side: ", result.Instance) end local intersection = result and result.Position or origin + direction*200 local distance = (origin - intersection).Magnitude bullet_clone.Size = Vector3.new(0.1, 0.1, distance) bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2) bullet_clone.Parent = game.Workspace:WaitForChild("laserbulletsfolder") or Instance.new("Folder", game.Workspace) game.Debris:AddItem(bullet_clone, 0.07) end)
ERROR:
Players.Character.Backpack.laser.clientside:22: attempt to perform arithmetic (sub) on nil and Vector3 - Client - clientside:22 08:50:23.279 Stack Begin - Studio 08:50:23.279 Script 'Players.Character.Backpack.laser.clientside', Line 22 - Studio - clientside:22 08:50:23.279 Stack End - Studio