Model Clone Issue

Hello Developers, I’m just asking for a way to teleport the stand model behind me every time the remote fires, and it does not matter where I’m facing.

When I face for example, “East”:
image
It will go behind me as I want,
but when I face any other direction for example, “North”:
image

It will not go behind me. What I want is to make the stand go behind me every time the remote gets fired, no matter where I’m facing.

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local AbilityOneRemote = ReplicatedStorage.Remotes.AbilityOne

local UserPoseAnimation = ReplicatedStorage.Animations.UserPose

AbilityOneRemote.OnServerEvent:Connect(function(Player)
	local PlayerCharacter = Player.Character
	local PlayerHumanoid = PlayerCharacter.Humanoid
	local PlayerStand = ReplicatedStorage.Stand:Clone()
	local StandCallSound = SoundService.OtherSFX.GoldExperience:Clone()
	local StandSummonSound = SoundService.OtherSFX["GE-Summon"]:Clone()
	local StandEffect = ReplicatedStorage.Effects.GiornoStand1.Middle:Clone()
	StandCallSound.Parent = PlayerCharacter.Head
	StandSummonSound.Parent = PlayerStand.Torso
	StandEffect.Parent = PlayerStand.Torso

	local UserPose = PlayerHumanoid:LoadAnimation(UserPoseAnimation)
	UserPose:Play()
	StandCallSound:Play()
	
	wait(0.15)
	StandSummonSound:Play()
	PlayerStand.Parent = PlayerCharacter

	local primaryPart = PlayerStand:WaitForChild("HumanoidRootPart")

	local offsetBehindPlayer = Vector3.new(-1.5, 0, 2.5)

	local function updateStandPosition()
		local playerPosition = PlayerCharacter.HumanoidRootPart.Position
		primaryPart.CFrame = CFrame.new(playerPosition + offsetBehindPlayer)
	end

	updateStandPosition()

	local weld = Instance.new("WeldConstraint")
	weld.Part0 = primaryPart
	weld.Part1 = PlayerCharacter.HumanoidRootPart
	weld.Parent = primaryPart
	wait(0.35)
	StandEffect:Destroy()
end)
1 Like

This might work:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local AbilityOneRemote = ReplicatedStorage.Remotes.AbilityOne

local UserPoseAnimation = ReplicatedStorage.Animations.UserPose

AbilityOneRemote.OnServerEvent:Connect(function(Player)
	local PlayerCharacter = Player.Character
	local PlayerHumanoid = PlayerCharacter.Humanoid
	local PlayerStand = ReplicatedStorage.Stand:Clone()
	local StandCallSound = SoundService.OtherSFX.GoldExperience:Clone()
	local StandSummonSound = SoundService.OtherSFX["GE-Summon"]:Clone()
	local StandEffect = ReplicatedStorage.Effects.GiornoStand1.Middle:Clone()
	StandCallSound.Parent = PlayerCharacter.Head
	StandSummonSound.Parent = PlayerStand.Torso
	StandEffect.Parent = PlayerStand.Torso

	local UserPose = PlayerHumanoid:LoadAnimation(UserPoseAnimation)
	UserPose:Play()
	StandCallSound:Play()
	
	wait(0.15)
	StandSummonSound:Play()
	PlayerStand.Parent = PlayerCharacter

	local primaryPart = PlayerStand:WaitForChild("HumanoidRootPart")

	local offsetBehindPlayer = Vector3.new(-1.5, 0, 2.5)
    local lookAtOffset = Vector3.new(-4, 2, 0) -- Adjust as needed

	local function updateStandPosition()
		local playerPosition = PlayerCharacter.HumanoidRootPart.Position
		primaryPart.CFrame = CFrame.lookAt(playerPosition + offsetBehindPlayer, playerPosition + lookAtOffset)
	end

	updateStandPosition()

	local weld = Instance.new("WeldConstraint")
	weld.Part0 = primaryPart
	weld.Part1 = PlayerCharacter.HumanoidRootPart
	weld.Parent = primaryPart
	wait(0.35)
	StandEffect:Destroy()
end)

No, this isn’t working; it teleports the stand in a 45-degree rotation and not behind me.

The lookAtOffset is meant to be adjusted as the comment I made says. Try setting it to Vector3.new(-1.5, 0, 0) and the problem should be fixed although if you change the offsetBehindPlayer value you will need to adjust it again to correct the angle

try replacing the code in the updateStandPosition function w this

local playerCF = PlayerCharacter.HumanoidRootPart.CFrame
primaryPart.CFrame = playerCF + playerCF.LookVector * offsetBehindPlayer
1 Like

That’s a very good suggestion so nice work dude! I tested it though and found that it doesn’t offset the stand to the right or left though so for that you’ll need to adjust the code to be like this:

local playerCF = PlayerCharacter.HumanoidRootPart.CFrame
primaryPart.CFrame = (playerCF + playerCF.LookVector * offsetBehindPlayer.Z) * (playerCF + playerCF.RightVector * offsetBehindPlayer.X)

Edit: Actually with further testing I found a better formula:

local cframe = PlayerCharacter.HumanoidRootPart.CFrame
primaryPart.CFrame = cframe + (cframe.LookVector * offsetBehindPlayer.Z + cframe.RightVector * offsetBehindPlayer.X)

Although I wouldn’t have found it if it wasn’t for your help @CZXPEK so thank you for giving me the idea

Thanks for the help, yall. I fixed it my way by adding a hitbox part once the player joins and welding the hitbox behind the player, then setting the player model position to that hitbox.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.