i recently made a fps game but the bullet hole thing doesn't work. it comes with a error that says Players.IEntity_303I.Backpack.LocalScript:22: attempt to perform arithmetic (add) on nil - heres the script :
local cam = workspace.Camera local Mouse = game.Players.LocalPlayer:GetMouse() local Hand = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Right Arm"):Clone() local Model = Instance.new("Model") Model.Name = game.Players.LocalPlayer.Name.."'s Model" Model.Parent = workspace Hand.Parent = Model Hand.Name = "RightArm1" game:GetService("RunService").RenderStepped:Connect(function() for i = 0,1,.0001 do wait() Hand.CFrame = Hand.CFrame:Lerp(cam.CFrame * CFrame.new(1,-1,-2), i) end end) Mouse.Button1Down:Connect(function() local Decalpart = Instance.new("Part") local hit,pos,normal = workspace:Raycast(Hand.Position,Hand.CFrame.LookVector) Decalpart.Transparency = 1 Decalpart.Size = Vector3.new(1,1,1) Decalpart.Parent = workspace Decalpart.CFrame = CFrame.new(pos,pos + normal) local decal = "rbxassetid://73737626" decal.Parent = Decalpart decal.Face = "Front" end)
workspace:Raycast returns RaycastResult which is Instance but let's call it a table with result properties, the properties are:
You would simply index it like this
local hit = workspace:Raycast(Hand.Position,Hand.CFrame.LookVector) if (hit) then print(hit.Normal) ... end
If nothing was hit, hit
in your case is nil so you should check if something was hit before indexing it.