#script stops working after death
1 messages · Page 1 of 1 (latest)
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
Player.CharacterAdded:Connect(function(character)
local viewmodel = game.ReplicatedStorage.ViewModel:Clone()
local RemoteEvent = game.ReplicatedStorage:WaitForChild("UpdateHeadAndArms")
local humanoid = character:WaitForChild("Humanoid"):WaitForChild("Animator")
local physicsService = game:GetService("PhysicsService")
local hum = viewmodel:WaitForChild("Humanoid")
viewmodel.Parent = Camera
viewmodel.PrimaryPart = viewmodel:WaitForChild("HumanoidRootPart")
local idle = hum:LoadAnimation(script.Animation)
if Player.Team == game.Teams.Red then
for _, part in pairs(viewmodel:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = "RedTeam"
end
end
else
for _, part in pairs(viewmodel:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = "BlueTeam"
end
end
end
for _, part in character:GetDescendants() do
if part:IsA("BasePart") then
part.CastShadow = true
end
end
idle:Play()
RunService.RenderStepped:Connect(function()
local cameraLookVector = Camera.CFrame.LookVector
viewmodel:PivotTo(
Camera.CFrame * CFrame.new(0, -1, -1)
)
if RemoteEvent then
RemoteEvent:FireServer(cameraLookVector)
end
end)
local tracks = {}
character.animTool.OnClientEvent:Connect(function(anim, play)
if play then
local track = hum:LoadAnimation(anim)
tracks[anim] = track
track:Play()
else
if tracks[anim] then
tracks[anim]:Stop()
tracks[anim] = nil
end
end
end)
if tool then
local othertool = viewmodel:FindFirstChildOfClass("Tool")
local clone = tool:Clone()
clone.Parent = viewmodel
clone.Handle.CFrame = CFrame.new()
if othertool then
othertool:Destroy()
end
if clone:FindFirstChild("IsMotored") then
local other = viewmodel.Torso:FindFirstChild("Motor6D")
if other then
other:Destroy()
end
local motor = Instance.new("Motor6D", viewmodel.Torso)
motor.Part0 = viewmodel["Right Arm"]
motor.Part1 = clone.Handle
else
local other = viewmodel.Torso:FindFirstChild("Weld")
if other then
other:Destroy()
end
local weld = Instance.new("Weld", viewmodel.Torso)
weld.Part0 = viewmodel["Right Arm"]
weld.Part1 = clone.Handle
end
end
end)
character:WaitForChild("Humanoid").Died:Connect(function()
viewmodel:Destroy()
return
end)
end)
so it basically works, until you die once, ut it doesnt totally break, its just that the animations cant stop
where is this script located
starter player
i mean, the script still runs, like everything is working perfectly expect the animations wont stop, thats so weird and specific
but ill test that
that did not work
** You are now Level 1! **
i can provide more context and scripts if you want
are there any errors on the output when you die?
not really
explain more what happens when you die
only the animations break?
no, so basically everything that you would expect to happen, happens. the animtions play and everything but it just doesnt stop
i can send a ss of the script so its less complicated
character.animTool.OnClientEvent:Connect(function(anim, play)
if play then
local track = hum:LoadAnimation(anim)
tracks[anim] = track
track:Play()
else
if tracks[anim] then
tracks[anim]:Stop()
tracks[anim] = nil
end
end
end)```
this is the part that plays the animations
look
i cant send the code because im too lazy rn
but what i think is happening
you said that the animations cant stop right
yeah
Characteradded fires everytime the character is added
what this means?
tracks is being created multiple times
and probably when you die once, it is trying to find the animation on the other tracks table
on the second life table if you get what i mean
i dont get what this means right now but i just gotta think about it a little
im new to scripting
you just need to get this table out of characteradded
yea
was about to say that
alr thanks bro 
btw i think it is safer to clean the table on the character added
not on the Died event
how are you cleaning the table
btw when you fire animTool you are inputting player, animation object, then true or false depending on whether you want it to play or stop
** You are now Level 2! **
what this one remote do
i just answered that lol
those are fired from tools
i put a print() inside the logic part where it stops the animation and it does not print anything
really?
i think i know what is causing that
what is it
can you try to print the tracks table inside the onclientevent
character.animTool.OnClientEvent:Connect(function(anim, play)
print(table)
if play then
local track = hum:LoadAnimation(anim)
tracks[anim] = track
track:Play()
else
tracks[anim]:Stop()
tracks[anim] = nil
end
end)
you mean like this?
yea
it prints some nonsense like this
00:49:49.585 ▼ {
["clear"] = "function",
["clone"] = "function",
["concat"] = "function",
["create"] = "function",
["find"] = "function",
["foreach"] = "function",
["foreachi"] = "function",
["freeze"] = "function",
["getn"] = "function",
["insert"] = "function",
["isfrozen"] = "function",
["maxn"] = "function",
["move"] = "function",
["pack"] = "function",
["remove"] = "function",
["sort"] = "function",
["unpack"] = "function"
it works in after death too but idk what this even means
huh
why is it printing table functions
thats crazy
well idk realy
what i think is that the script is not stopping the right animation
uhh
could you try
character.animTool.OnClientEvent:Connect(function(anim, play)
local id = anim.AnimationId
if play then
local track = hum:LoadAnimation(anim)
tracks[id] = track
track:Play()
else
if tracks[id] then
tracks[id]:Stop()
tracks[id] = nil
end
end
end)
changing the current animation part to that
?
nah
i mean local table
is there any difference?
if not this didnt work either, im really wasting your time sorry but if youre still interested maybe i can send an example code from a tool:
script.Parent.Activated:Connect(function()
if turn then
turn = false
slash1:Play()
animtool:FireClient(player, script.Parent.Slash1, true)
cool(tool.Cooldown.Value)
task.delay(2, function()
turn = true
end)
else
turn = true
slash2:Play()
animtool:FireClient(player, script.Parent.Slash2, true)
cool(tool.Cooldown.Value)
end
end)
nah im okay but im just curious why is it not working
me too bro its like why would it start playing if its not gonna stop
maybe u gotta wait someone with more experience to guide you
i cant rlly see any errors on it
mybe it is a little thing
alr bro thanks for the efforts and time tho
wait
you said
play is true
or false
right
yep
i probably did and didnt send you that part because i didnt want you to read stuff that arent related
i know i did because before you die you can stop the animations
oh wait
i just realised
you needed to print(tracks)
not print(table)
damn why didnt i see that
right
my bad
01:03:49.418 ▼ {
[Instance(Idle,CB4A697C3B9D7A37)] = Idle,
[Instance(Slash1,18B0BCDB3C205D57)] = Slash1,
[Instance(Slash2,E4EEE1D290A63D47)] = Slash2
} - Client - Arms:55
and then
Players.sigmaironingtable.PlayerScripts.Arms:63: attempt to index nil with 'Stop' - Client - Arms:63
arms is the name of the script btw
** You are now Level 3! **
huhhhhhhhhhhhh
are you using the code i sent?
`
character.animTool.OnClientEvent:Connect(function(anim, play)
local id = anim.AnimationId
if play then
local track = hum:LoadAnimation(anim)
tracks[id] = track
track:Play()
else
if tracks[id] then
tracks[id]:Stop()
tracks[id] = nil
end
end
end)
this one
but still why is it saying that tracks is nil
01:07:17.173 ▼ {
["rbxassetid://103372683553799"] = Slash1,
["rbxassetid://137015450951644"] = Idle,
["rbxassetid://81446549403565"] = shoot
} - Client - Arms:56
not tracks i mean the animation
is the error still happening?
tried to index nil with stop? no
i think the error is still here
you never send a false signal
what is cool?
hold on
local animtool = nil
local tool = script.Parent
local hitbox = tool.Hitbox
local character = nil
local player = nil
local touched = false
script.Parent.Equipped:Connect(function()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local slash1 = humanoid:LoadAnimation(script.Parent.Slash1)
local slash2 = humanoid:LoadAnimation(script.Parent.Slash2)
local idle = humanoid:LoadAnimation(script.Parent.Idle)
character = script.Parent.Parent
player = game.Players:GetPlayerFromCharacter(character)
local turn = true
local other = character.Torso:FindFirstChild("Motor6D")
if other then
other:Destroy()
end
animtool = character:FindFirstChild("animTool")
idle:Play()
animtool:FireClient(player, script.Parent.Idle, true)
character:FindFirstChild("Right Arm"):WaitForChild("RightGrip"):Destroy()
local motor6 = Instance.new("Motor6D", character.Torso)
motor6.Part0 = character:FindFirstChild("Right Arm")
motor6.Part1 = script.Parent.Handle
script.Parent.Unequipped:Connect(function()
idle:Stop()
animtool:FireClient(player, script.Parent.Idle, false)
end)
local function cool(time)
tool.Enabled = false
task.wait(time)
tool.Enabled = true
touched = false
end
script.Parent.Activated:Connect(function()
if turn then
turn = false
slash1:Play()
animtool:FireClient(player, script.Parent.Slash1, true)
cool(tool.Cooldown.Value)
task.delay(2, function()
turn = true
end)
else
turn = true
slash2:Play()
animtool:FireClient(player, script.Parent.Slash2, true)
cool(tool.Cooldown.Value)
end
end)
end)
hitbox.Touched:Connect(function(hit)
if hit:IsDescendantOf(character) then return end
if tool.Enabled == true then return end
if touched then return end
touched = true
local hmn = hit.Parent:FindFirstChild("Humanoid")
if hmn then
hmn:TakeDamage(tool.Damage.Value)
end
end)
thats the full script of the tool
cool is a function for cooldowns
it disables and enables the tool
well
there is alot of things there
first mistake is that you are recreating the variable turn everytime that you equip the tool
second one is that you are creating a activated event inside a equipped event
this will duplicate the activated event everytime you equip the tool
and yeah you are never sending a false signal to stop the animation
i think what you can do is firing it again after the cooldown but now with false
i think this is the time when AI would rlly be useful now
AI will probably explain way better htan me
than me*
dont copy the code from it oblivously, try to understand
i already asked ai like a few times and didnt understand 😭
bro im gonna have to go now thanks for the effort man
ill try what you said tho
you can always say "explain this in simpler terms"
good luck
thanks again
there is alot of begginer mistaskes there but for sure you will fix them
but yea dont be mad to make these mistakes because failing is a great way to evolve
ok so
i tryed to read everything
but its hard
right here
wait
i dont think that is it
ok so
first question
which animations wont stop
and in what way
its helpfull if u have a vid
action type animations will stop automatically, youre only required to stop idle animations
ill try to get it on video but my pc isnt that great
its just from an example tool i dont think its really related to the actual script. but all you do from a tool script is you fire a remote event inside the character called animTool
animTool:FireClient(player, animation object, bool)
if you input an animation and true on the server side, it should animate the rig on the local side. if you input false, it should stop the animation
ok
so
i think i know what is happening
on the first script that u sent
u are using characteradded
actually wait a little
le me confirm
ye
that is weird
even the things that i think are the problem actually are not
i would think that it is bc the script is creating a new connection every time your character loads
but i dont think that is it
im tryna fix that right now i didnt know connections worked like that
until now
im kinda new
ye
connections still run even after your character dies
if u want do undo the connection u would need to do sum like
local con = blabla:Connect(blablabla)
(when u want to disconnect)
con:Disconnect()
** You are now Level 12! **
u can also disconnect inside the function of the connect
kinda like a return
but for connections
just tested it forget abt it
i thought u could but u cant
soo uhh
debugging with prints time
on ts part of the code
can u put a print of the tracks, anim and the play
ping me when u do
sorry i was doing something i just came back
it print this after i print tracks, anim, play
{
[Instance(Idle,E506FB849A4A2D3E)] = Idle,
[Instance(Slash1,4794CFFF69CB4FE)] = Slash1
} Slash1 true
when i unequip after dying once it prints this
{[Instance(Slash1,FE9D41C7A543723)] = Slash1
} Idle false
it looks pretty normal and it should stop the animation but idk whats happening
i was gonna record in roblox but it doesnt even work in the actual game 🙏
hmm
ok so
lets just try some basic things
i saw that u are placing the animations inside the character
put them on replicated storage and load them from there
u can make a folder if u want
the animations are inside the tool
** You are now Level 4! **
but ok
that didnt work
im gonna try to disconnect the functions first to see if that works
btw can u send me that "print(tracks, anim, play)" after u placed them in the replicated storage
do you want me to share the game with you temporarily? i can do that
okk
it prints the same thing
reminder that literally any time something stops working when the character is reset USUALLY HAS SOMETHING TO DO WITH THE CHARACTER
** You are now Level 35! **
seen this problem a FEW times in the past two days
and I don't mean literally just a few.
ts is so solvable if all character/animation/humanoid/whatnot data is maintained correctly WITH the character state rather than remotely.
I strongly recommend making this more built on states.
can you elaborate on what you mean by built on states?
character scripts at the very least