I was making a pistol, and I wanted the bullet trail to stick to the tip of the gun for a few seconds. However, I encountered a strange error which read,
"13:20:33.030 - ServerScriptService.MainScript:29: attempt to perform arithmetic on a userdata value".
I can't understand what it means, as all I was trying to do was edit the trail's CFrame. I'll put in that small part of the script, where the trail was created and the CFrame was supposed to be edited.
local distance = (tool.Handle.CFrame.p - position).magnitude if game.Workspace:FindFirstChild(player.Name.."'s Trajectory") then game.Workspace:FindFirstChild(player.Name.."'s Trajectory"):Destroy() end local trajectory = Instance.new("Part", game.Workspace) local smoke = serverStorage.SmokeParticle:Clone() smoke.Parent = tool.Handle trajectory.BrickColor = BrickColor.new("Institutional white") trajectory.Material = "SmoothPlastic" trajectory.Name = player.Name .. "'s Trajectory" trajectory.Transparency = 0.5 trajectory.Anchored = true trajectory.Locked = true trajectory.CanCollide = false trajectory.Size = Vector3.new(0.3, 0.3, distance) for i = 0, distance, 6 do trajectory.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance) / 2 wait(0.0001) end smoke:Destroy()
The error occurs in the for loop, the line with the CFrame. "position" was defined earlier on, in the LocalScript that fired the event. Help would be appreciated.
Edit: The error is at line 29 in the actual script, but in this chunk of code it's at line 17.
Edit2: I mainly fixed the problem by changing line 17 to this: "trajectory.CFrame = CFrame.new(tool.Handle.CFrame.p, position), CFrame.new(0, 0, -distance / 2)" , but now the trajectory's position comes at the handle's position, causing the trajectory to be behind the player as well. Any help?
Fixed errors. New code chunk:
local distance = (tool.Handle.CFrame.p - position).magnitude if game.Workspace:FindFirstChild(player.Name.."'s Trajectory") then game.Workspace:FindFirstChild(player.Name.."'s Trajectory"):Destroy() end local trajectory = Instance.new("Part", game.Workspace) local smoke = serverStorage.SmokeParticle:Clone() smoke.Parent = tool.Handle trajectory.BrickColor = BrickColor.new("Institutional white") trajectory.Material = "SmoothPlastic" trajectory.Name = player.Name .. "'s Trajectory" trajectory.Transparency = 0.5 trajectory.Anchored = true trajectory.Locked = true trajectory.CanCollide = false trajectory.Size = Vector3.new(0.3,0.3,distance) for i = 0,distance,6 do trajectory.CFrame = CFrame.new(tool.Handle.CFrame.p,position) * CFrame.new(0,0,-distance / 2) wait(0.0001) end smoke:Destroy()