Hello,
Yesterday I tried to reset with those codes below but it didn't work.
I have many animations, I give an example: it changes properties when I click on the button.
01 | button 3 = script.Parent |
02 |
03 | function ClickButton () |
04 | if button 3. BrickColor = = BrickColor.new( 'Persimmon' ) then |
05 | button 3. BrickColor = BrickColor.new( 'Mulberry' ) |
06 | else |
07 | button 3. BrickColor = BrickColor.new( 'Persimmon' ) |
08 | end |
09 | end |
10 |
11 | button 3. ClickDetector.MouseClick:connect (ClickButton) |
I made a clone into Lighting. I created a Script with this code:
1 | local clone = workspace.Animations.button 3 :Clone() |
2 | clone.Parent = game.Lighting |
(button3 is inside Workspace > Animations (a folder))
After, i create a Script inside ServerCharacterScripts, with this code:
01 | script.Parent.Humanoid.Died:Connect( function () |
02 | for i,v in pairs (workspace:GetDescendants()) do |
03 | if v:IsA( "Script" ) then |
04 | v:Destroy() |
05 | end |
06 | end |
07 | for i,v in pairs (game.Lighting:GetDescendants()) do |
08 | if v:IsA( "Script" ) then |
09 | v:Clone().Parent = workspace |
10 | end |
11 | end |
12 | end ) |
When I play, I have two problems: - the button keeps changed properties after character dies - I can't click anymore to change properties after death
I'd like that when the character dies, the player restart the game at the last spawn and repeat all the ''operations'' from the last CheckPoint.
Thank you for your help.
I think this is a better alternative than listening to a humanoid dying since this fires when a character dies and his player is/has been removed.
1 | game:GetService( "Players" ).PlayerAdded:Connect( function (Player) |
2 | Player.CharacterRemoving:Connect( function () |
3 | -- do code |
4 | end ) |
5 | end ) |
It works if the button were clicked before death. But when it's not clicked, it changes as if it was clicked, after respawn. I put this code in a script into ServerScriptService.
01 | button 3 = script.Parent.Parent.Workspace.Animations.button 3 |
02 |
03 | game:GetService( "Players" ).PlayerAdded:Connect( function (Player) |
04 | Player.CharacterRemoving:Connect( function (ClickButton) |
05 | if button 3. BrickColor = = BrickColor.new( 'Persimmon' ) then |
06 | button 3. BrickColor = BrickColor.new( 'Mulberry' ) |
07 | else |
08 | button 3. BrickColor = BrickColor.new( 'Persimmon' ) |
09 | end |
10 | end ) |
11 | end ) |
12 |
13 | button 1 = script.Parent.Parent.Workspace.Animations.button 1 |
14 |
15 | game:GetService( "Players" ).PlayerAdded:Connect( function (Player) |