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)
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.
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)
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:
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.