You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I would like the box not to be rigid but to tilt when the player looks up or down. -
What is the issue? Include screenshots / videos if possible!
I don’t know how to approach this. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have written the following code
local model = script.Parent.Parent
local prompt = script.Parent
local animation = script.Animation
local distanceZ = -2.7--Model distance from character/ how far the model will be from the character
local distanceY = -0.5--Model distance from the ground
local animationTrack = nil
local owner = nil
prompt.Triggered:Connect(function(player)
local ModelClone = model:Clone()
ModelClone.Anchored = false
ModelClone.Parent = workspace
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
if not animationTrack then
animationTrack = humanoid:LoadAnimation(animation)
end
if not ModelClone:FindFirstChildWhichIsA("WeldConstraint") and owner == nil and not player:FindFirstChild("Carry") then
local CarryValue = Instance.new("BoolValue", player)
CarryValue.Name = "Carry"
local weld = Instance.new("WeldConstraint", ModelClone)
ModelClone.CanCollide = false
ModelClone.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, distanceY, distanceZ)
weld.Part0 = ModelClone
weld.Part1 = character.HumanoidRootPart
owner = player.Name
animationTrack:Play()
elseif ModelClone:FindFirstChildWhichIsA("WeldConstraint") and owner == player.Name and animationTrack and player:FindFirstChild("Carry") then
animationTrack:Stop()
ModelClone:FindFirstChildWhichIsA("WeldConstraint"):Destroy()
player:FindFirstChild("Carry"):Destroy()
ModelClone.CanCollide = true
owner = nil
animationTrack = nil
end
--<<Death Detector>>--
humanoid.Died:Connect(function()
pcall(function()
player.Carry:Destroy()
end)
end)
end)