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