Animation does not launch after being in the game after a bit

This script is supposed to start an animation when triggered.

My friend (@Misthero21) is having a problem getting this script to work as it just stops working after a bit. And it does not give any errors that would help fix it. I think after a while, the FireServer() stops giving 1 or probably 0. two people with the same swords make that the fireserver stops working for one player.

This is a local script and it’s supposed to talk with the servers.

local change = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local second = false

mouse.Button1Down:Connect(function()
    if second == false then
        second = true
    change:FireServer(1)
    wait(0.1)
    change:FireServer(0)
    wait(0.2)
    second = false
    end
    
end)

And this second one is a script of the animation itself. This is a server script.

local change = script.Parent
local running = false

change.onServerEvent:Connect(function(player, num)
    local char = player.Character
    local tool = char.sword
    
    if num == 1 then
        if running == false then
        running = true
    
    wait(0.03)
    tool.GripUp = Vector3.new(0.926, 0, 0.378)
    
    wait(0.03)
    tool.GripUp = Vector3.new(0.707, 0, 0.707)

    wait(0.03)
    tool.GripUp = Vector3.new(0.5, 0, 0.866)

    wait(0.03)

    tool.work.Value = 1
    tool.GripUp = Vector3.new(0, 0, 1)
    wait(0.06)
    tool.GripUp = Vector3.new(0.5, 0, 0.866)

    wait(0.03)
    tool.GripUp = Vector3.new(0.707, 0, 0.707)

    wait(0.03)
    tool.GripUp = Vector3.new(0.926, 0, 0.378)

    wait(0.03)
    
    tool.GripUp = Vector3.new(1, 0, 0)
    tool.work.Value = 0
    wait(0.06)
    wait(2)

    running = false
    end
        
    else if num == 0 then
        print("no")
    end
    end
end)

He has tried adding debounce as he was thinking it may be a network delay.

2 Likes

Why is “Change” the parent of a local script? Change shouldn’t be there try ReplicatedStorage and change “Change” to

local change = game.ReplicatedStore:WaitForChild("Change")

The second script should be a serverscript but I believe you’ve already knew that but you never know lol.

The “Change” mistake was fixed but it sadly has not fixed the main problem. And the second script is already serverscript.

Proper indentation goes a long way, The fixed code Server side is below.

How is the code working now? I noticed in the server script you have an extra end at the end of you code, which should give you an error?

change.onServerEvent:Connect(function(player, num)
    local char = player.Character
    local tool = char.sword
    
    if num == 1 then
        if running == false then
            running = true
    
            wait(0.03)
            tool.GripUp = Vector3.new(0.926, 0, 0.378)
    
            wait(0.03)
            tool.GripUp = Vector3.new(0.707, 0, 0.707)

            wait(0.03)
            tool.GripUp = Vector3.new(0.5, 0, 0.866)

            wait(0.03)

            tool.work.Value = 1
            tool.GripUp = Vector3.new(0, 0, 1)
            wait(0.06)
            tool.GripUp = Vector3.new(0.5, 0, 0.866)

            wait(0.03)
            tool.GripUp = Vector3.new(0.707, 0, 0.707)

            wait(0.03)
            tool.GripUp = Vector3.new(0.926, 0, 0.378)

            wait(0.03)
    
            tool.GripUp = Vector3.new(1, 0, 0)
            tool.work.Value = 0
            wait(0.06)
            wait(2)

            running = false
        end
        
    elseif num == 0 then --[[ I put this `elseif` statement within the first `if` statement. 
    it was originally only going to trigger if the running `if` statement failed.
--]]
        print("no")
    end
    --- I removed the extra "end".
end)

This did not fix the problem but it did clean the script up a tad bit.
two people with same swords make that the fireserver stops working for one player.

you can’t make posts for other people,please tell your friend to make a post. This is in devforum’s ToS

This is a group project and we work on things together.

1 Like

you two script it? If not he needs to make a topic

I see now.

That is because the running variable is not exclusive to each character. The server shares the running variable with everyone, so in actuality it will only work for one person at a time.

Try using a bool value for each character’s sword during the event so that the running variable will look like this:

    local char = player.Character
    local tool = char.sword
    local running = tool.running

This way, you will not have to change much of the code, while keeping the code working properly.

Adjusted Code:

local change = script.Parent
--- Removed the running variable for the server.

change.onServerEvent:Connect(function(player, num)
    local char = player.Character
    local tool = char.sword
    local running = tool.running --- added the bool value here. DO NOT make it 'running.Value', that will not change the value when you want it to.
    
    if num == 1 then
        if running.Value == false then -- Since this is a bool, you have to add '.Value' now. 
            running.Value = true
    
            wait(0.03)
            tool.GripUp = Vector3.new(0.926, 0, 0.378)
    
            wait(0.03)
            tool.GripUp = Vector3.new(0.707, 0, 0.707)

            wait(0.03)
            tool.GripUp = Vector3.new(0.5, 0, 0.866)

            wait(0.03)

            tool.work.Value = 1
            tool.GripUp = Vector3.new(0, 0, 1)
            wait(0.06)
            tool.GripUp = Vector3.new(0.5, 0, 0.866)

            wait(0.03)
            tool.GripUp = Vector3.new(0.707, 0, 0.707)

            wait(0.03)
            tool.GripUp = Vector3.new(0.926, 0, 0.378)

            wait(0.03)
    
            tool.GripUp = Vector3.new(1, 0, 0)
            tool.work.Value = 0
            wait(0.06)
            wait(2)

            running.Value = false
        end
        
    elseif num == 0 then
        print("no")
    end
end)
2 Likes

It looks like it’s working thx m8.

1 Like