#Script can't find a part and gui, please help

4 messages · Page 1 of 1 (latest)

keen galleonBOT
#

studio** You are now Level 1! **studio

barren forge
#

local player = game.Players.LocalPlayer
local horseFolder = workspace.Horses
local proximityZone = workspace.HorseProximityZone
local horseMenuUI = player.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)

steel stratus
#
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)