Attempt to perform arithmetic (sub) on Vector3 and number

I tried to make a slain system and jumpscare for my game but I keep getting an error from Line 41 How do I fix this?

                                        Line 41
                                           ↓
                                           ↓

if (character:WaitForChild("Torso").Position - workspace:WaitForChild("Filter").JsScene:WaitForChild("RDummy").HumanoidRootPart).magnitude<10 then
	
local userInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local cam = workspace.CurrentCamera
local tInfo3 = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tFov = tweenService:Create(cam, tInfo3, {FieldOfView = 36})

local player = game:GetService("Players").LocalPlayer	
local playergui = player.PlayerGui

local jumpscare_ui = playergui:WaitForChild("Jumpscare_UI")

local tFov = tweenService:Create(cam, tInfo3, {FieldOfView = 36})
local tNoiseImg = tweenService:Create(jumpscare_ui.NoiseIMG, tInfo3, {ImageTransparency = 0.4})

local Rake = workspace.Filter.JsScene.RDummy
local RakeHumanoid = workspace.Filter.JsScene.RDummy.Humanoid

local rakeScream = jumpscare_ui.RakeScream

local Hit = jumpscare_ui.Hit2
local Susto = jumpscare_ui.Susto
local Death4 = jumpscare_ui.Death4

local BloodHourAnimation = RakeHumanoid:LoadAnimation(Rake:FindFirstChild("Animation")); -- Animation
local allplayer = game:GetService("Players"):GetPlayers()

local selfname = script.Parent:WaitForChild("Humanoid").DisplayName

local slained = script:WaitForChild("Slained")

local players = game:GetService("Players")

local camerapart = Rake:FindFirstChild("HumanoidRootPart"):FindFirstChild("CameraPart")
local character = player.Character or player.CharacterAdded:Wait()

repeat wait() until script.Parent:FindFirstChildOfClass("Humanoid")
script.Parent.Humanoid.Changed:Connect(function()
	script.Parent.Humanoid.Died:Connect(function()
		for _,player in pairs(players:GetPlayers()) do
			if (character:WaitForChild("Torso").Position - workspace:WaitForChild("Filter").JsScene:WaitForChild("RDummy").HumanoidRootPart).magnitude<10 then
				tNoiseImg:Play()
				tFov:Play()
				local clonedgui = slained:Clone()
				clonedgui.TextLabel.Text = character.Name.. "was slained"
				clonedgui.Parent = player:WaitForChild("PlayerGui")
				cam.CameraType = Enum.CameraType.Scriptable
				script:WaitForChild("CFrameFix").Disabled = false
				rakeScream:Play()
				rakeScream:Play()
				Death4:Play()
				Susto:Play()
				BloodHourAnimation:Play()
				wait(0.2)
				cam.CFrame = camerapart.CFrame
				wait(0.51)   
				Hit:Play()
				wait(1.2)
				workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
				script:WaitForChild("CFrameFix").Disabled = true
			end
		end
	end)
end)

You don’t say HumanoidRootPart.Position here. That is probably one of your issues.

It fixed the error but jumpscare is not playing.

Assuming this is a local script, where is it placed?

It is placed under StarterCharacterScripts.

I suppose that you first add prints in the Died events cause I suspect it isn’t firing
If it doesn’t print then you should remove the Humanoid.Changed event since it’s extravagant as the died event will fire anyways.

I removed the Humanoid.Changed still the jumpscare still wont play. :frowning:

What does this equal

workspace:WaitForChild(“Filter”).JsScene:WaitForChild(“RDummy”).HumanoidRootPart.Position).magnitude

I’m sorry, what did you mean by this?

You want it to be <10 so what does it equal?
Put a print above the if statement.

print(character:WaitForChild(“Torso”).Position - workspace:WaitForChild(“Filter”).JsScene:WaitForChild(“RDummy”).HumanoidRootPart.Position).magnitude

Sorry didn’t realize it didn’t copy the whole line

It did not print anything (ithirtyi)

You appear to have Forgotten the Position in HumanoidRootPart

local Magnitude = (character:WaitForChild("HumanoidRootPart").Position - workspace:WaitForChild("Filter").JsScene:WaitForChild("HumanoidRootPart").Position).Magnitude 
if Magnitude < 10 then
-- code
end

LocalScript does not run in ‘StarterCharacterScript’.

Where does it run? (ithirtyichar)

I am getting an error

Check if the HumanoidRootPart Exists

LocalScript | Roblox Creator Documentation. As it said :

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

• A Player’s Backpack, such as a child of a Tool
• A Player’s character model
• A Player’s PlayerGui
• A Player’s PlayerScripts.
• The ReplicatedFirst service

Forgot the RDummy

local Magnitude = (character:WaitForChild(“HumanoidRootPart”).Position - workspace:WaitForChild(“Filter”).JsScene.RDummy:WaitForChild(“HumanoidRootPart”).Position).Magnitude
if Magnitude < 10 then
– code
end

1 Like

Move the ‘LocalScript’ to ‘StarterPlayerScript’ and change the code to this and see if it works.

local players = game:GetService("Players")
local userInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local cam = workspace.CurrentCamera
local tInfo3 = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tFov = tweenService:Create(cam, tInfo3, {FieldOfView = 36})

local allplayer = players:GetPlayers()
local localplayer = players.LocalPlayer
local playergui = localplayer.PlayerGui

local jumpscare_ui = playergui:WaitForChild("Jumpscare_UI")

local tFov = tweenService:Create(cam, tInfo3, {FieldOfView = 36})
local tNoiseImg = tweenService:Create(jumpscare_ui.NoiseIMG, tInfo3, {ImageTransparency = 0.4})

local Rake = workspace.Filter.JsScene.RDummy
local RakeHumanoid = Rake.Humanoid
local rakeScream = jumpscare_ui.RakeScream
local Hit = jumpscare_ui.Hit2
local Susto = jumpscare_ui.Susto
local Death4 = jumpscare_ui.Death4
local BloodHourAnimation = RakeHumanoid:LoadAnimation(Rake:FindFirstChild("Animation")); -- Animation
local slained = script.Slained
local camerapart = Rake.HumanoidRootPart.CameraPart

localplayer.CharacterAdded:Connect(function(character)
    local humanoid, root = character:WaitForChild("Humanoid", 9999), character:WaitForChild("HumanoidRootPart", 9999)
    local selfname = humanoid.DisplayName
    humanoid.Died:Connect(function()
        if (root.Position - Rake.HumanoidRootPart.Position).Magnitude < 10 then
            tNoiseImg:Play()
	        tFov:Play()
	        local clonedgui = slained:Clone()
 	       clonedgui.TextLabel.Text = character.Name.. "was slained"
            clonedgui.Parent = playergui
	        cam.CameraType = Enum.CameraType.Scriptable
             script:WaitForChild("CFrameFix").Disabled = false
	        rakeScream:Play()
   	       rakeScream:Play()
 	       Death4:Play()
    	    Susto:Play()
	        BloodHourAnimation:Play()
            wait(0.2)
	        cam.CFrame = camerapart.CFrame
	          wait(0.51)   
	        Hit:Play()
	        wait(1.2)
	        cam.CameraType = Enum.CameraType.Custom
	        script:WaitForChild("CFrameFix").Disabled = truel
        end
    end)
end)

The anything under the StarterCharacterScripts gets cloned and parented to the character model so the LocalScript still does run.