Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

:GetMarkerReachedSignal() fires way too early?

Hello! I haven't been able to find an answer to my question above so I decided to come here to try and get it solved.

I have an local animation script in StarterGui>Components>Viewmodel: Image

Inside the localscript there is some code which should make shotgun shells spawn near the slider:

function playShoot()
	if game.ReplicatedStorage:WaitForChild("Components").Events.GiveClientInfo.Value == true then -- "GiveClientInfo" is a Bool Value which I used to get data from server that the player clicked 
		Hold:Stop()
		Shoot.Looped = false -- Making sure for no errors
		Shoot:Play()
		if Shoot:GetMarkerReachedSignal("Eject Shells") then
			local shell = rep.Components.Models.Shells.Union:Clone()
			shell.Parent= workspace["Ejected Shells"]
			shell.CFrame = weapon.Ejector.CFrame + Vector3.new(0 , 1.5, 0)
			game:GetService("Debris"):AddItem(shell, 6)
		end
		Hold:Play()
	end
end

Here is the Animation Window where I set up the marker: Image

But when played (In studio play mode as well as actually playing it), it fires as soon as I click (the shell is supposed to clone when the animation where the slider is shown appears): GIF

This is my first time messing with animation tracks and animation markers.

If any more info is needed, I will edit the post to add those details as soon as I can. Thanks!

Major Details Edit: The comments in the script was wrong, GiveClientInfo is a bool value not a remote event, I got confused with REs with the same name format, this has been corrected.

14 comments

0

I am getting an about blank error with the images for some reason, I will try to get that fixed

0

Sorry, I haven't messed with animations since before KeyframeReached was deprecated, in favor of :GetMarkerReachedSignal(), so I'm rusty. When you run the animation in the editor, does it look like it should?

0

And are you certain that you have the marker in the appropriate place?

0

The animation marker is placed correctly, if needed i can send an image

0

An RBXScriptSignal can't be used a boolean expression, nor will it yield like you think it will in this context. To properly achieve what you're attempting, replace the conditional scope with "Shoot:GetMarkerReachedSignal("Eject Shells"):Wait()" at line 6.

0

I tried doing that but that skips my animation for some odd reason, I'll quickly send a gif, I'll retry

0

If compared the animation here is skipped, the weird part is it happens at the correct time.

0

It shouldn't.

0

Is it a hardware problem?

0

The script changes is identical but "if then end" are removed/replaced

0

This post was originally going to be posted on dev forums but I don't have the permissions to post there yet, wondering if this is a bug

0

Should I provide the script which detects if the player is clicking**? Also no errors or anything in the output except a print message that i used to detect if the player clicked

0

Major Detail edit, please check it out, thanks

2 answers

✓ Accepted answer

You're using :GetMarkerReachedSignal() incorrectly. That method returns a RBXScriptSignal, which you might already be familiar with. Here's an example of how to use it correctly:

local markerReached = animationTrack:GetMarkerReachedSignal(markerName)

markerReached:Connect(function(...)
	print('animation marker was reached!')
end)

Every time the marker named markerName is reached, the markerReached event will fire. Check out the API reference, too.

6 comments

0

I'll quickly try that, I did try this method but 2-9 shells spawned causing lag, I'll retry

0

This worked! The only problem is 3+ shells spawn using this method, how do I fix that? Script Image just in case: https://gyazo.com/155006aaafe7d81f5fd01a32fea13bfb

0

Does it print 3 times, as well?

0

Checking

0

Kind of random, I clicked twice(the server message seperates the different click attempts): https://gyazo.com/5b1665cf6e06a00de40685eb05d5ec7e

[The question is already solved by Optikk, just giving the answer script for any other person with the same issue(?)]

Script:

local function animate()
	local shell = rep.Components.Models.Shells.Union:Clone()
	shell.Parent= workspace["Ejected Shells"]
	shell.CFrame = weapon.Ejector.CFrame + Vector3.new(0 , 1, 0)
	game:GetService("Debris"):AddItem(shell, 6)
end

function playShoot()
	if game.ReplicatedStorage:WaitForChild("Components").Events.GiveClientInfo.Value == true then
		Hold:Stop()
		Shoot.Looped = false -- Making sure for no errors
		Shoot:Play()
		Hold:Play()
	end
end

Shoot:GetMarkerReachedSignal("Eject Shells"):Connect(animate)

Note: My implementation of the :GetMarkerReached() was wrong and the method I was using stacks it, it has been fixed

This discussion is preserved as it was. New answers, comments, and votes are closed.