#arrow not facing target

1 messages · Page 1 of 1 (latest)

warped panther
#

i am trying to make an arrow face a target which is a part called "JobPickup1" to pick up a package (not a physical package it is set by an attribute "HasPackage") then when has package is set to true i want the arrow to face the destinations "Dropoffpoint1" "Dropoffpoint2" and "Dropoffpoint3" to show the player where to deliver the package to, i have gotten the arrow to hover over the players head and follow them. but i cant get it to face the correct direction. yes i have used chatgpt for this cos im not good at scripting (i am trying to learn) ill put the local script and script in the chat of the post does anyone know why it isnt working, it just faces random directions it spins like its facing something but it doesnt seem like its actually pointing to a specific location

#

local script

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer

RunService.RenderStepped:Connect(function()
    local char = player.Character
    if not char then return end

    -- Get HumanoidRootPart
    local hrp = char:FindFirstChild("HumanoidRootPart")
    if not hrp then return end

    -- Find arrow
    local arrow = char:FindFirstChild("ActiveArrow")
    if not arrow or not arrow:IsA("Model") or not arrow.PrimaryPart then return end

    -- Get the target position
    local targetPos = arrow:GetAttribute("Target")
    if not targetPos then return end

    -- Set position above the HumanoidRootPart (adjust Y height)
    local offset = Vector3.new(0, 5, 0) -- Change Y to adjust height
    local arrowPos = hrp.Position + offset

    -- Flatten target to match player's height for rotation (ignoring Y)
    local flatTarget = Vector3.new(targetPos.X, arrowPos.Y, targetPos.Z)

    -- Direction from arrow to target
    local direction = (flatTarget - arrowPos).Unit
    if direction.Magnitude == 0 then return end -- Prevent invalid direction

    -- Rotate arrow to face the target
    local lookCFrame = CFrame.lookAt(arrowPos, flatTarget)

    -- Apply the position and rotation to the arrow
    arrow:SetPrimaryPartCFrame(lookCFrame)
end)
#

script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mapFolder = game.Workspace.Map

game.ReplicatedStorage.ArrowEvent.OnServerEvent:Connect(function(player)
    print("Arrow event fired by:", player.Name)

    local character = player.Character
    if not character then return end

    local currentJob = player:GetAttribute("CurrentJobIndex")
    local hasJob = player:GetAttribute("HasJob")
    local hasPackage = player:GetAttribute("HasPackage")

    if not hasJob then return end

    local targetPart
    if not hasPackage then
        targetPart = mapFolder:FindFirstChild("JobPickup" .. tostring(currentJob))
    else
        targetPart = mapFolder:FindFirstChild("Dropoffpoint" .. tostring(currentJob))
    end

    if not targetPart then return end

    -- Clone the arrow and set it above the player's head
    local arrowTemplate = ReplicatedStorage:FindFirstChild("DirectionArrow")
    if not arrowTemplate then return end

    local arrow = arrowTemplate:Clone()
    arrow.Name = "ActiveArrow"
    arrow.Parent = character
    arrow:SetAttribute("Target", targetPart.Position)

    local hrp = character:FindFirstChild("HumanoidRootPart")
    if hrp then
        -- Position the arrow above the player
        arrow.CFrame = hrp.CFrame * CFrame.new(0, 5, 0)
    end
end)
tropic hare
#

chatgpt..

warped panther
#

what do u want me to do magically acquire knowledge, i am learning and just using that to help me as i go

#

thats like hating on a guy who cant walk for using a walking stick

#

can someone just help me

drifting seal
#

no, as you said learn, this is not at your level so keep learning your level

warped panther
#

bro seriously ur not gonna help cos its "not my level"

drifting seal
#

yh

#

I dont want you to get a thing scripted by me first cuz you aint gonna learn shit and second its ai script

warped panther
#

how am i meant to learn it theres nothing about this anywhere

#

if i had a working script infront of me i could read it and learn from it this is why i use ai cos im good at learning from stuff that is infront of me

drifting seal
#

you're going just learn what is happening on the script, and thats not good

warped panther
#

why would that be bad that means i can get a better understanding of it