#Script can't find a part and gui, please help
4 messages · Page 1 of 1 (latest)
local player = game.Players.LocalPlayer
local horseFolder = workspace.Horses
local proximityZone = workspace.HorseProximityZone
local horseMenuUI = player.PlayerGuigame:GetService("RunService").Heartbeat:Connect(function()
for _, horse in pairs(horseFolder:GetChildren()) do
-- Check if horse has entered the proximity zone
local horseDistance = (horse.Position - proximityZone.Position).Magnitude
local playerDistance = (player.Character.HumanoidRootPart.Position - proximityZone.Position).Magnitude-- Check if player and horse are both within proximity if horseDistance <= proximityZone.Size.X/2 and playerDistance <= proximityZone.Size.X/2 then local horseMenu = horseMenuUI:FindFirstChild("HorseMenuInteraction" .. horse.Name) if horseMenu then horseMenu.Enabled = true end else local horseMenu = horseMenuUI:FindFirstChild("HorseMenuInteraction" .. horse.Name) if horseMenu then horseMenu.Enabled = false end end endend)
The script runs before the workspace loads. In such case, you have to use :WaitForChild("")
local player = game.Players.LocalPlayer
local horseFolder = game.Workspace:WaitForChild("Horses")
local proximityZone = game.Workspace:WaitForChild("HorseProximityZone")
local horseMenuUI = player:WaitForChild("PlayerGui")
game:GetService("RunService").Heartbeat:Connect(function()
for _, horse in pairs(horseFolder:GetChildren()) do
-- Check if horse has entered the proximity zone
local horseDistance = (horse.Position - proximityZone.Position).Magnitude
local playerDistance = (player.Character.HumanoidRootPart.Position - proximityZone.Position).Magnitude
-- Check if player and horse are both within proximity
if horseDistance <= proximityZone.Size.X/2 and playerDistance <= proximityZone.Size.X/2 then
local horseMenu = horseMenuUI:FindFirstChild("HorseMenuInteraction" .. horse.Name)
if horseMenu then
horseMenu.Enabled = true
end
else
local horseMenu = horseMenuUI:FindFirstChild("HorseMenuInteraction" .. horse.Name)
if horseMenu then
horseMenu.Enabled = false
end
end
end
end)
** You are now Level 1! **