I am making a horror game and I want to make a jumpscare when a part is touched so I made a Touched function that moves a different part to the player and it makes a sound.
But, it doesn’t work for some reason. i have no idea why, there are no error messages or anything in the script.
Ive looked on youtube and have asked people but unfortunately, I haven’t gotten anything back from them.
Can you provide more here? What is “game.Workspace.Jumpscare” and why are you playing it?
Also, you wrote: game.Workspace.Monster = Vector3.new(100, 100, 100)
This wouldn’t work because you have to write: game.Workspace.Monster.Position = Vector3.new(100, 100, 100)
Remember to write the property that you’re changing not just the instance!
Also, if you want something to move on the player’s character, you can get the “hit” of the touched event. For example, you can rewrite your code like this:
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
game.Workspace.Monster.Position = hit.Parent.HumanoidRootPart.Position
game.Workspace.Jumpscare:Play()
end
end)
Always check for a humanoid in touched events because anything can touch a part, including another part, so you need to make sure that a player is touching it by using an if statement.
Ah, I didn’t know that Monster is a model; I thought it was a part. “Position” is a property that parts have. Models don’t have this property which explains why “Position” isn’t a member of Monster. Can you show me the children of the monster model?
Piggybacking off of dodle’s answer, I would recommend you to set a primary part for the monster, and then use :SetPrimaryPartCFrame() to adjust the whole monster’s position.
local Part = script.Parent
local function jumpscare()
game.StarterGui.YourJumpScareGui.Enabled = true -- UI looks better in jumpscares imo, if you want to make it a mesh/model, teleport it in front of the player.
game.Workspace.Jumpscare.Playing = true -- Make sure the volume is up
end
Part.Touched:Connect(jumpscare)
If this doesn’t work, let me know. Also, are there any errors in the output?