Animation Problem

I’m new to scripting, and I wanted to test my skills by doing a Tycoon game in which Monkeys collect bananas. (lol) The Monkeys have an animation that drops the banana by cloning a Banana Mesh in ReplicatedFirst and putting it on Workspace.

The problem is that sometimes the script clones two Banana Meshes instead of one at the same time, and I don’t know how it’s happening.

I tried using Time Position, Debounce variables and Animation Events, but all of those gave the same result.

This is the script.

local monkey = script.Parent.Monkey
local animationTrack = monkey.Humanoid:LoadAnimation(monkey.Grab)
local bananaPos = monkey.BananaPos
local Debris = game:GetService("Debris")

animationTrack:Play()


animationTrack:GetMarkerReachedSignal("BananaDrop"):Connect(function()
	local banana = game:GetService("ReplicatedFirst").Banana:Clone()
	banana.Parent = game.Workspace
	banana.Position = bananaPos.Position
	banana.Anchored = false
	Debris:AddItem(banana)
end)

If someone has a solution I would be very grateful.

1 Like

It might be that BananaDrop is there twice in the animation? Try replacing :Connect with :Once to see if that’s the case

It seems to work, but after generating the first banana, it stops generating more.

Edit: Also has the same issue, spawning two bananas instead of one.

that’s really strange, maybe try putting them in ReplicatedStorage instead?

A few problems I thought might be your issue:

  • The banana model in replicated first contains 2 bananas. (Maybe one banana mesh is parent under the 1st)
  • The marker is in your animation twice.
  • You have the same script running twice.
1 Like

Hello, sorry for replying late, I went to sleep.

  1. I checked ReplicatedFirst and it only contains 1 banana.
  2. I also checked the Animation Markers, and there was only one.
  3. Same thing, only one script, I even deactivated other scripts and the problem persists.

Thanks for replying and sorry again for answering so late :sweat_smile:

This is because your AnimationTrack is constant, meaning you don’t assign animation every time.
When AnimationTrack uses function “GetMarketReachedSignal” it connects to the function that runs your script. And each time they will increase, as they are just being connected. To fix the issue you have to make a variable which will have the value of this whole function and then disable it.

local monkey = script.Parent.Monkey
local animationTrack = monkey.Humanoid:LoadAnimation(monkey.Grab)
local bananaPos = monkey.BananaPos
local Debris = game:GetService("Debris")
local Function = nil
animationTrack:Play()


Function = animationTrack:GetMarkerReachedSignal("BananaDrop"):Connect(function()
	Function:Disconnect()
	local banana = game:GetService("ReplicatedFirst").Banana:Clone()
	banana.Parent = game.Workspace
	banana.Position = bananaPos.Position
	banana.Anchored = false
	Debris:AddItem(banana)
end)

The script works, but the problem persists.

I’m starting to think that this is a Roblox Studio Bug.

Hmm. Maybe, try this?

local monkey = script.Parent.Monkey
local animationTrack = monkey.Humanoid:LoadAnimation(monkey.Grab)
local bananaPos = monkey.BananaPos
local Debris = game:GetService("Debris")

animationTrack:Play()


animationTrack:GetMarkerReachedSignal("BananaDrop"):Connect(function()
if not game.Workspace:FindFirstChild("Banana") then
	local banana = game:GetService("ReplicatedFirst").Banana:Clone()
	banana.Parent = game.Workspace
	banana.Position = bananaPos.Position
	banana.Anchored = false
	Debris:AddItem(banana)
end
end)

It works, the thing is that I have multiple Monkeys cloning the same banana, so they will stop producing bananas.

Maybe if I do an individual banana to each Monkey?

I don’t know, you can try to do this.

I just did that, the problem seems to appear less than before, but it still happens.

Edit: I tried printing the Animation Time Position every time the problem happens, and it prints the EXACT same value.

image

  1. Try use Humanoid.Animator
local animationTrack = monkey.Humanoid.Animator:LoadAnimation(monkey.Grab)
  1. Check out if it has Action type
    image

I tried to do the same thing as you and it works fine. Idk any others solutions

Maybe the issue in the banana, when it spawns it clones itself

I just realized that the issue only happens in Roblox Studio playtests.

I’ve played my game in the Roblox app several times and it just doesn’t happen, I don’t know if it’s just luck though.

So yeah, it was always a Roblox Studio bug or something like that. :slightly_smiling_face:

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