I’m currently making a mini horror game and I’m having issues with a local script… I’m not sure why, but even after the clone of the monster has been destroyed, the script continues to run and I still get damaged when looking away. Here is my script.
Local Script
local run = game:GetService("RunService")
local camera = workspace.CurrentCamera
local part = workspace:WaitForChild("d")
local player = game.Players.LocalPlayer.Character.Humanoid
local function onRenderedFrame()
local position, visible = camera:WorldToScreenPoint(part.Position)
if visible then
print("LOOK")
elseif not visible then
print("NOT LOOK")
player.Health -= 0.5
end
wait(20)
return
end
run.RenderStepped:Connect(onRenderedFrame)
Monster Script
local trigger = game.Workspace.LOOKTrigger
local plr = game:GetService("Players")
local main = script.Parent
local clone = main:Clone()
plr.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoidrootpart = character:WaitForChild("HumanoidRootPart")
trigger.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Torso") then
trigger:Destroy()
print("Look worked.")
clone.Parent = game.Workspace
clone.CFrame = humanoidrootpart.CFrame * CFrame.new(0,1,-15)
print("Clone WOrked")
wait(20)
clone:Destroy()
end
end)
end)
end)
If you need any more information let me know. Sorry it’s kinda messy.