So I have a script that drops coins on the enemy’s death and they just fall on the ground. I’ve tried to make it so after 0.5 seconds each of the coins would launch themselves at the player’s uppertorso and destroy themselves / play a particle effect, but I can’t get it to work. I’ve tried changing the velocity of the coins and tweening them but they can’t go to the player for some reason.
Can you show your script, as well as the code of your previous attempts?
Death Script:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local coin = game.ReplicatedStorage:WaitForChild("Coin")
local function shootCoin()
local newCoin = coin:Clone()
newCoin.Parent = game.Workspace
newCoin.Position = character.HumanoidRootPart.Position + Vector3.new(math.random(-3, 3), 1, math.random(-3, 3))
local randomDirection = Vector3.new(math.random(-3, 3), 10, math.random(-10, 10)).unit
newCoin.Velocity = randomDirection * 50
wait(0.2)
end
humanoid.Died:Connect(function()
local killer = humanoid:FindFirstChild("creator")
if killer then
local player = killer.Value
local randXp = math.random(1, 2)
local randCoinCount = math.random(5, 15)
player.leaderstats.Xp.Value += randXp
player.leaderstats.Coins.Value += randCoinCount
for i = 1, randCoinCount do
shootCoin()
end
end
end)
Before I just tried to change the velocity direction of the coins and tried to tween them, but I deleted that code.
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local coin = game.ReplicatedStorage:WaitForChild("Coin")
local function shootCoin()
local newCoin = coin:Clone()
newCoin.Parent = game.Workspace
newCoin.Position = character.HumanoidRootPart.Position + Vector3.new(math.random(-3, 3), 1, math.random(-3, 3))
game.TweenService:Create(newCoin, TweenInfo.new(0.2), {Position = character.HumanoidRootPart.Position}):Play()
wait(0.2)
end
edit: removed code that i didn’t change
Look into either AlignPosition or Bezier curves. Either one should get you to your desired result but Bezier curves are significantly more complicated.