Hi all
i am making a horror game and i have made a script which triggers a jumpscare when a player touches the trigger but for some reason it is not working
Problem 1.the camera angle wont change
Problem2.The Sound wont play
Here’s the script
local Camera = game.Workspace.Camera
local Angle = game.Workspace.Angle
local Doll = game.Workspace.Doll
local Trigger = script.Parent
local Scream = script.Parent.Scream
Trigger.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid")then
Trigger:Destroy()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Angle.CFrame
Scream:Play()
Scream.Volume = 3
wait(0.9)
Camera.CameraType = Enum.CameraType.Custom
end
end)
Hi,
I think your problem is that you put “Music” in Trigger.
After Humanoid hit Trigger it Destroys Trigger and all items he contains ( Music, Script ).
You should fix it or change Trigger:Destroy() line
local Camera = game.Workspace.Camera
local Angle = game.Workspace.Angle
local Doll = game.Workspace.Doll
local Trigger = script.Parent
local Scream = script.Parent.Scream
Trigger.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid")then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Angle.CFrame
Scream:Play()
Scream.Volume = 3
wait(0.9)
Trigger:Destroy()
Camera.CameraType = Enum.CameraType.Custom
end
end)
I’m not sure because I mostly script GUI.
But you should move Trigger:Destroy() to the end
local Camera = game.Workspace.Camera
local Angle = game.Workspace.Angle
local Doll = game.Workspace.Doll
local Trigger = script.Parent
local Scream = script.Parent.Scream
Trigger.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid")then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Angle.CFrame
Scream:Play()
Scream.Volume = 3
wait(0.9)
Camera.CameraType = Enum.CameraType.Custom
Trigger:Destroy()
end
end)
local work = game:GetService("Workspace")
local Camera = work:WaitForChild("Camera")
local Angle = work:WaitForChild("Angle")
local Doll = work:WaitForChild("Doll")
local Trigger = script.Parent
local Scream = script.Parent.Scream
Trigger.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid")then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Angle.CFrame
Scream:Play()
Scream.Volume = 3
wait(0.9)
Camera.CameraType = Enum.CameraType.Custom
Trigger:Destroy()
end
end)
local Camera = game.Workspace.Camera
local Angle = game.Workspace.Angle
local Doll = game.Workspace.Doll
local Trigger = script.Parent
local Scream = script.Parent.Scream
Trigger.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid")then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Angle.CFrame
Scream.Volume = 3
Scream:Play()
wait(0.9)
Trigger:Destroy()
Camera.CameraType = Enum.CameraType.Custom
end
end)
Is this a server script? The server’s camera does not belong to any particular player, you’ll need to fire the specific client (which should be “jumpscared”) and manipulate their camera locally.