Hello, I want to make my ‘entity’ rage when the player is not ‘hiding’, like when the entity is nearby and if the player does not ‘hide’, then it will play the sound and then ‘speed up’.
This is the entity module script:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local p183 = {}
function p183.FindPlayers(model)
local players = Players:GetPlayers()
local characters = {}
for i, player in ipairs(players) do
if player.Character then
table.insert(characters, player.Character)
end
end
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Include
overlapParams.FilterDescendantsInstances = characters
local collisions = workspace:GetPartsInPart(model.Smoke, overlapParams)
for index, obj in ipairs(collisions) do
if obj.Name == "HumanoidRootPart" then
local rayDirection = obj.Position - model.P183.Position
local result = workspace:Raycast(model.P183.Position, rayDirection)
if result and result.Instance then
local hit = result.Instance
if hit == obj or hit:FindFirstAncestor(obj.Parent.Name) then
local FindPlayer = Players:GetPlayerFromCharacter(obj.Parent)
if not FindPlayer.Hiding.Value then
obj.Parent.Humanoid.Health = 0
end
end
end
end
end
end
function p183.LerpTo(model, target)
local alpha = 0
local speed = 650
local distance = (model.PrimaryPart.Position - target.Position).Magnitude
local relativeSpeed = distance / speed
local startCFrame = model.PrimaryPart.CFrame
local loop = nil
local reachedTarget = Instance.new("BindableEvent")
loop = RunService.Heartbeat:Connect(function(delta)
p183.FindPlayers(model)
local goalCFrame = startCFrame:Lerp(target.CFrame, alpha)
model:PivotTo(goalCFrame)
alpha += delta / relativeSpeed
if alpha >= 1 then
loop:Disconnect()
reachedTarget:Fire()
end
end)
reachedTarget.Event:Wait()
end
function p183.Navigate(model, prevNum, maxNum, generatedRooms, loopAmount)
local currentLoop = 0
local p183State = "isGoing" or "isComing"
repeat
currentLoop +=1
if p183State == "isGoing" then
task.wait(2)
for i = prevNum, maxNum do
local room = generatedRooms[i]
p183.LerpTo(model, room.Entrance)
local waypoints = room:FindFirstChild("Waypoints")
if waypoints then
for i=1, #waypoints:GetChildren() do
p183.LerpTo(model, waypoints[i])
end
end
p183.LerpTo(model, room.Exit)
end
p183State = "isComing"
else
for i = maxNum, prevNum, -1 do
local room = generatedRooms[i]
p183.LerpTo(model, room.Exit)
local waypoints = room:FindFirstChild("Waypoints")
if waypoints then
for i=#waypoints:GetChildren(), 1, -1 do
p183.LerpTo(model, waypoints[i])
end
end
p183.LerpTo(model, room.Entrance)
end
p183State = "isGoing"
end
until currentLoop == loopAmount
end
function p183.New(number, generatedRooms)
local enemyModel = game.ReplicatedStorage.Enemies.P183:Clone()
local prevNum = number - 6
local maxNum = number + 1
local prevRoom = generatedRooms[prevNum]
if not generatedRooms[maxNum] then
maxNum = #generatedRooms
end
local maxRoom = generatedRooms[maxNum]
local loopAmount = 4
enemyModel:PivotTo(prevRoom.Entrance.CFrame)
enemyModel.Parent = workspace
enemyModel.P183.Ambience:Play()
p183.Navigate(enemyModel, prevNum, maxNum, generatedRooms, loopAmount)
enemyModel:Destroy()
end
return p183
Any help is appreciated, thanks.
PS: I have already my hiding value set up.