#i need help

34 messages · Page 1 of 1 (latest)

gaunt adder
#

@sterile hatch is there any error in the output?

sterile hatch
#

no

#

the script works but everytime the i loop is done the orientation resets to the default orientation

gaunt adder
#

What is the value of "maxDistance " it isn't in the script?

sterile hatch
#

its the local Distance i just accidentally removed the max while writing the message

analog wagonBOT
#

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

gaunt adder
#
            local lookat =CFrame.lookAt(script.Parent.Position, nearestPlayer.Character.Head.Position)
            script.Parent.CFrame = CFrame.new(script.Parent.Position):Lerp(lookat, i)
        end
        script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, nearestPlayer.Character.Head.Position)```
Line 23-26.

There is some repeating code, first it tries to lerpt it with a position then it just sets it for some reason.
This might be the issue.
@sterile hatch
sterile hatch
#

thats the script that moves the orientation to look at the player the thing im confused about is when that i loop is over the orientation resets wich is wy there is a second lookat because i tried to fix the problem

#

im trying to make the orientation not reset when the i loop is over

gaunt adder
sterile hatch
#

my thought was that the orientation might reset because of the i loop ending wich is why i tried to set the orientation to look at the player after the i loop to make it look at the player again

gaunt adder
#

It doesn't seem to be the issue.

#

@sterile hatch Will adding more wait, I saw the part is turning 180 degress in the same direction everytime.

#

Oh it was just the original starting point.

#

@sterile hatch I removed the lerp and set directly the lookAt CFrame. The lerp seems to be the problem.

sterile hatch
#

yes i know but what im wondering if theres a way i can have the lerp but not have it reset everytime

gaunt adder
#

Is there any reason, why you are using this over tween service?

#

TweenService works smoother for animations.

#

And is simplier.

sterile hatch
gaunt adder
#

Try it.

sterile hatch
#

i'll try to implement it i guess

gaunt adder
#

Good luck.

sterile hatch
#

i tried making it a tweenservice but i got the error unable to cast to discitonary

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

local part = script.Parent

local tweenservice = game:GetService("TweenService")

local maxDistance = 50

local info = TweenInfo.new(
    0.5, 
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)


while true do
    wait(0.01)
    local nearestPlayer, nearestDistance
    for _, player in pairs(Players:GetPlayers()) do
        local character = player.Character
        local distance = player:DistanceFromCharacter(part.Position)
        if not character or 
            distance > maxDistance or
            (nearestDistance and distance >= nearestDistance)
        then
            continue
        end
        nearestDistance = distance
        nearestPlayer = player
        local goal = {CFrame.lookAt(script.Parent.Position, nearestPlayer.Character.Head.Position)}
        local twoon = tweenservice:Create(script.Parent, info, goal)
        twoon:Play()
    end
end
#

@gaunt adder local twoon = tweenservice:Create(script.Parent, info, goal) this returned unable to cast to discionary

gaunt adder
#

@sterile hatch You have to do goal.CFrame = CFrame.lookAt(script.Parent.Position, nearestPlayer.Character.Head.Position)

#

I would also name the table goals, as it can have multiple goals.

sterile hatch
#

i know i've already fixed it

gaunt adder
sterile hatch
#

yeah