Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

:GetMarkerReachedSignal() fires way too early?

Asked by 4 years ago
Edited 4 years ago

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.

0
I am getting an about blank error with the images for some reason, I will try to get that fixed shephali 3 — 4y
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? Gey4Jesus69 2705 — 4y
0
And are you certain that you have the marker in the appropriate place? Gey4Jesus69 2705 — 4y
0
The animation marker is placed correctly, if needed i can send an image shephali 3 — 4y
View all comments (10 more)
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. Ziffixture 6913 — 4y
0
I tried doing that but that skips my animation for some odd reason, I'll quickly send a gif, I'll retry shephali 3 — 4y
0
If compared the animation here is skipped, the weird part is it happens at the correct time. shephali 3 — 4y
0
It shouldn't. Ziffixture 6913 — 4y
0
Is it a hardware problem? shephali 3 — 4y
0
The script changes is identical but "if then end" are removed/replaced shephali 3 — 4y
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 shephali 3 — 4y
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 shephali 3 — 4y
0
Major Detail edit, please check it out, thanks shephali 3 — 4y

2 answers

Log in to vote
0
Answered by
Optikk 499 Donator Moderation Voter
4 years ago
Edited 4 years ago

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.

0
I'll quickly try that, I did try this method but 2-9 shells spawned causing lag, I'll retry shephali 3 — 4y
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 shephali 3 — 4y
0
Does it print 3 times, as well? Gey4Jesus69 2705 — 4y
0
Checking shephali 3 — 4y
View all comments (2 more)
0
Kind of random, I clicked twice(the server message seperates the different click attempts): https://gyazo.com/5b1665cf6e06a00de40685eb05d5ec7e shephali 3 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

[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

Answer this question