Hello, this doesn’t seem to want to start running, also any tips to making it perform better would be awesomee
local RunService = game:GetService("RunService")
local EyeEventRemote = game:GetService("ReplicatedStorage"):WaitForChild("EyeEvent")
local Eye = game.Workspace.HappyHome.Home.EyeOfSauron.Eye
local Map = game:GetService("Workspace"):FindFirstChild("HappyHome"):Clone()
local Permitted = {28220859}
function FindNearest()
local ChosenPlayer = nil
local ChosenDistance = math.huge
for _,Player in ipairs(game.Players:GetPlayers()) do
local PrimaryPart = Player.Character and Player.Character.PrimaryPart
local NewDistance = PrimaryPart and (Eye.Position - PrimaryPart.Position).Magnitude
if PrimaryPart and ChosenDistance > NewDistance then
ChosenDistance = NewDistance
ChosenPlayer = Player
end
end
return ChosenPlayer and ChosenPlayer.Character
end
game.Players.PlayerAdded:Connect(function(player)
if table.find(Permitted, player.UserId) then
player.Chatted:Connect(function(msg)
if msg == "!EyeEvent" then
print("Said eye event")
if game.Workspace.HappyHome then
print("Map already there")
MinigameActive = true
print(MinigameActive)
else
print("Not there.")
local MapClone = Map:Clone()
MapClone.Parent = workspace
MinigameActive = true
end
elseif msg == "!EndEvent" then
MinigameActive = false
end
end)
end
end)
local Detector = Instance.new("Part")
Detector.Anchored = true
Detector.CanCollide = false
Detector.Transparency = 0.5
Detector.Color = Color3.fromRGB(255, 0, 0)
Detector.Size = Vector3.new(1, 1, 1) * 4
MinigameActive = false
local LaserPart = Instance.new("Part")
LaserPart.Color = Color3.fromRGB(255, 0, 0)
LaserPart.Anchored = true
LaserPart.CanCollide = false
LaserPart.Parent = workspace
function startGame()
print("Started")
local Target = FindNearest()
local TargetPrimaryPart = Target or Target.PrimaryPart
local laser_Thickness = .5
local rayOriginPart = Eye
local rayTargetPart = Target.HumanoidRootPart
local RayCastParameters = RaycastParams.new()
RayCastParameters.FilterDescendantsInstances = Eye.Parent:GetChildren()
RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist
local results
--local rayTargetPart = rootPart
local function castRay()
local origin = rayOriginPart.CFrame.Position
local rayTarget = rayTargetPart.CFrame.Position
local direction = (rayTarget - origin)
results = workspace:Raycast(origin, direction, RayCastParameters)
if not results then
results = {Position = rayTarget}
end
local distance = (results.Position - origin).Magnitude
print("Casted ray")
game.ReplicatedStorage.EyeEvent:FireAllClients(origin, rayTarget, distance, LaserPart)
end
game.ReplicatedStorage.EyeEvent.OnServerEvent:Connect(function(Player, clientResults)
if clientResults ~= nil and results ~= nil then
local difference = ((clientResults.Position - results.Position) * Vector3.new(1, 1, 1)).Magnitude
if difference < 5 then
task.wait(2)
Player.character.Humanoid:TakeDamage(5)
end
end
end)
LaserPart.Touched:Connect(function(hit)
wait(1)
if hit and hit.Parent and not hit:IsDescendantOf(workspace.HappyHome) and not hit.Parent:IsA("Accessory") or hit:IsA("Accessory") then
local humanoid = hit.Parent.Humanoid
humanoid:TakeDamage(5)
wait(1)
elseif hit:IsA("Accessory") then
print("Accessory")
elseif hit:IsDescendantOf(workspace.HappyHome) then
local hitPos = hit.Position
hit:Destroy()
local DetectorCopy = Detector:Clone()
DetectorCopy.Position = hit.Position
DetectorCopy.Touched:Connect(function()
end)
DetectorCopy.Parent = workspace
local PartsTouching = DetectorCopy:GetTouchingParts()
DetectorCopy:Destroy()
for _, Part in pairs(PartsTouching) do
if Part:IsDescendantOf(workspace.HappyHome) then
Part:BreakJoints()
Part:ApplyImpulse(Vector3.new(math.random(0, 50), math.random(10, 100), math.random(0,50)))
end
end
hit:ApplyImpulse(Vector3.new(math.random(1, 50), math.random(-100, 500), math.random(1, 50)))
--[[local Explosion = Instance.new("Explosion")
Explosion.DestroyJointRadiusPercent = 0
Explosion.Position = hitPos
Explosion.BlastPressure = 10000
Explosion.BlastRadius = 5
Explosion.Visible = true
Explosion.Parent = hit.Parent
wait(5)
Explosion.Hit:Connect(function(hit, distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage(0)
else
hit:BreakJoints()
end
end)]]
end
end)
RunService.Stepped:Connect(castRay)
end
while MinigameActive == true do
startGame()
end
For those who want to help optimize I can send you the client sided.