I’m trying to write code to allow an oxygen tank to become attached to the players body. I’m having an issue where the model only works if the player is orientated a certain way. I included a video with a short script to demonstrate this issue.
I’ve tried rotating the model based on the player’s orientation, but that doesn’t seem to resolve my issue. Any suggestions on how to go about fixing this?
local part = script.Parent
local ServerStorage = game:GetService("ServerStorage")
local DEBOUNCE = 2
local locked = false
part.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and locked == false then
locked = true
local Character = Player.Character
local Clone = ServerStorage.Tank_2:Clone()
Clone.Parent = workspace
local Part = Clone.Handle
local RightUpperLeg = Character:WaitForChild("UpperTorso")
-- Remove any lingering welds
for _, v in pairs(Part:GetChildren()) do
if v:IsA("Weld") then
v:Destroy()
end
end
Clone:PivotTo(CFrame.new(RightUpperLeg.Position))
local modelCFrame = Clone:GetPivot()
local Weld = Instance.new("Weld", Part)
-- Y + 0.25 to make it on the back instead of inside the torso. Rotate by 90 because it's position in server storage
Weld.C0 = RightUpperLeg.CFrame:ToObjectSpace(CFrame.new(Part.CFrame.X, Part.CFrame.Y + 0.25, Part.CFrame.Z) * CFrame.Angles(0, math.rad(90), 0))
Weld.Part0 = RightUpperLeg
Weld.Part1 = Part
Weld.Enabled = true
task.wait(DEBOUNCE)
Clone:Destroy()
locked = false
end
end)