Position is wrong?

Context: Im making a healing potion for my game and I want it to appear as a clone in the workspace to make it look like the character drop the consumable on use. The model does work but the position is not what I am trying to achieve.

Have a look at the script, please respond if there is something wrong!

local Tool = script.Parent
local Player = Tool:FindFirstAncestorWhichIsA("Player")
local Animation = Tool.Animation:WaitForChild("DrinkAnim")
local SoundFolder = Tool.Sounds or Tool.Handle:GetDescendants()
local HealPotionModel = game.ReplicatedStorage.ConsumablesModel.HealingPotion
local PositionToClone = Player.Character:WaitForChild("Healing Potion").Handle.Position

local isPlaying = false

local function playToolAnimation()
	if isPlaying then return end

	local player = game.Players:GetPlayerFromCharacter(Tool.Parent)
	if not player then return end

	local character = player.Character
	if not character then return end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	local animator = character:FindFirstChild("Animator") or humanoid:FindFirstChild("Animator")
	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	local animationTrack = animator:LoadAnimation(Animation)
	isPlaying = true
	SoundFolder.DrinkSound:Play()
	SoundFolder.DrinkSound.Parent = Tool.Handle
	animationTrack:Play()

	animationTrack:GetMarkerReachedSignal("DrinkEnd"):Connect(function()
		-- SoundFolder.DrinkFinishedSound:Play()
		SoundFolder.DrinkFinishedSound.Parent = Tool.Handle
		wait(0.1)
		local clonedModel = HealPotionModel:Clone()
		clonedModel.Parent = workspace
		clonedModel.Position = (Vector3.new(PositionToClone))
		clonedModel.Rotation = (Vector3.new(PositionToClone))
		Tool:Destroy()
	end)

	animationTrack.Stopped:Connect(function()
		isPlaying = false
	end)
end

Tool.Activated:Connect(playToolAnimation)

Here is also a video about the current problem:

2 Likes

Looks like you are setting PositionToClone at the top of the file. That position will be wherever your player was when it executed. Try getting the drop position closer to when you want to drop.

4 Likes

Just-in-case: If clonedModel is a Model, then you’ll need to use either PivotTo or MoveTo to set its position

What @Astr0Derp said is also correct, you’ll need to fetch the handle’s position just before you intend to drop the Tool


@DarkHazardOff

By the way, you currently have a memory leak, since you’re not disconnecting these connections:

A quick but dirty fix is to use Once instead of Connect, which will automatically disconnect the connections after they’re fired. You should exercise caution when creating connections within another connection (or inside of infinite loops)

2 Likes

i say you use CFrame, but the people in the chat are also correct

2 Likes

Hey there, thanks for your answer and sorry about the long delay, I was stucked in bed because I got sick ):

I’m gonna hop on Roblox Studio and let you know if it works!

2 Likes

Also, the “handle” is a part, here is the tool’s tree if needed!
image

1 Like

After rewatching the video, what @Astr0Derp recommended should fix your issue with the clonedModel being placed in the wrong location

Do take note of the memory leak, though :wink:

1 Like

What line would you recommend?

1 Like

I did use :once instead of :connect, thanks for the tip!! :wink:

2 Likes

First thing to try is prob just to set the Handle position to in front of the player right after (or before) you parent the tool to workspace. Something like:

clonedModel.Handle.Position = character.PrimaryPart.Position + Vector3.new(0, 0, -3)

If it’s supposed to be a used and discarded bottle, then that may be enough. It shouldn’t be anchored, so the physics should let it fall and possibly tumble. You’ll want to see what happens and adjust from there. There may be a TouchInterest inside the handle that needs to be deleted or you might just pick it back up.

There’s a list of things to consider once you’re getting the kind of drop/placement you want: Do you want it to be able to be picked up again? Does the dropped item need to be a tool? Should it drop to the ground using physics or should it float or something else? etc. It’s a process; each step forward reveals new issues and possibilities.

2 Likes

This was the correct solution, thanks!

1 Like