Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Strange error, attempt to perform arithmetic on userdata?

Asked by 5 years ago
Edited 5 years ago

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?

0
full code needed, up to line 29 greatneil80 2647 — 5y
0
The error is at line 17 in this chunk of code. In the actual script it's line 29. Ultimate_Miner64 45 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago

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()
0
The rules of the website state that you must explain what you did and explain to the asker what went wrong in their script so that they can learn from your answer and the experience. User#21908 42 — 5y
Ad

Answer this question