Hey everyone!
I have a script for my collectibles. When they’re touched, it anchors the player, then tweens the model to above the player. That works, except for it doesn’t get positioned properly. It’s either behind the player’s current position, or if it’s jumped on, way above where it should be. The model itself does have a script to allow it to spin, however that’s not the issue. Here’s the full script. (sorry if it’s bad, still trying to get better at scripting)
local RunService = game:GetService("RunService")
local event = game:GetService("ReplicatedStorage").RemoteEvents.PrismEvents:WaitForChild("Collected")
local ts = game:GetService("TweenService")
local name = script.Parent.PrismName
local color = script.Parent.PrismColor
local info = TweenInfo.new(
0.2,
Enum.EasingStyle.Back,
Enum.EasingDirection.InOut,
0,
false,
0
)
script.Parent.Collision.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
script.Parent.Collision.Spin.Enabled = false
event:FireClient(player, name.Value, color.Value)
local character = hit.Parent
local hrp = character:FindFirstChild("HumanoidRootPart")
local head = character:FindFirstChild("Head")
if not hrp or not head then return end
hrp.Anchored = true
task.wait()
local headCFrame = head.CFrame
local goal = {}
goal.CFrame = headCFrame * CFrame.new(0, 4, 0)
local tween = ts:Create(script.Parent.Collision, info, goal)
tween:Play()
task.wait(4)
hrp.Anchored = false
script.Parent:Destroy()
end)