I’m trying to make it so when you press a TextButton,the player’s death animation which is a script,will replace eachother,for example,you press the “Ragdoll”,you ragdoll after death,you press “Fade” you fade out after death.I’ve already tried multiple ways to make something like this,but i just don’t have enough experience.
So do you want to clone death animation script to character and change it with gui?
listen,here is what I wanna do,so there are 2 buttons , one is for Ragdoll other is for fade,when you press ragdoll,do smth,so the ragdolldeath script will work and the fade script won’t work.when pressing fade button,ragdoll death won’t work but fade death will work
maybe there is any other better way to do so,I’ll be glad to know.
You can create a server script in starterplayerscripts and hold your current death animation in it
In the script you connect a function when a player’s character spawns and connect died event to the character’s humanoid, create functions or modules for death animations and on death check current animation, then apply animation
Note:the player in this script in starterplayerscripts is script.Parent.Parent(as i remember)
You can create a String Value somewhere the player have access to, such as among other datastore values or in the player dirrectly. When clicking a button, change this value to be the name of the selected death. Then, create a LocalScript
in StarterCharacterScript
OR a Script
in ServerScriptService
, with different modules as children, for which each of them handle a different death effect.
Exemple of a Script in ServerScriptService
-- Roblox Services --
local PlayerService = game:GetService("Players")
--------------------------------------------------
-- Local Functions --
local function WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
Humanoid.Died:Connect(function()
local Module = script:FindFirstChild(DeathEquipped.Value)
if Module then
require(Module).PlayDeathEffect()
end
end)
end
local function SetupPlayer(Player)
local DeathEquipped = Player:WaitForChild("DeathEquipped", 300)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid", 300)
WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
Player.CharacterAdded:Connect(function(NewCharacter)
Character = NewCharacter
Humanoid = Character:WaitForChild("Humanoid", 300)
WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
end)
end
--------------------------------------------------
-- Signal Connections --
PlayerService.PlayerAdded:Connect(function(NewPlayer)
task.spawn(SetupPlayer, NewPlayer)
end)
so if i add any modules,how do i modify the script?
You don’t need to make any modifications. Simply name each module with the name of your death effects, such as “Ragdoll” or “Fade.” Then, in each module, name the main function “PlayDeathEffect”, where you will script the corresponding effect.
This way, if the value of your equipped death effect is “Ragdoll,” the system will automatically search for the module with the same name and execute it.
Yep, don’t forget to send the Humanoid as argument in the main script.
require(Module).PlayDeathEffect() -- PlayDeathEffect(Humanoid)
hmm,it seems,that i’ve misunderstood something,and it won’t work
This was an example script, it use a value as a reference to know which death effect is currently equipped. You don’t have this value yet, you need to create it yourself and put it somewhere you are the most comfortable with, such as with other player data values, then modify this line of code if needed.
local DeathEquipped = Player:WaitForChild("DeathEquipped", 300)
it is in there,or is it a bad place to be?
-- Roblox Services --
local PlayerService = game:GetService("Players")
--------------------------------------------------
-- Local Functions --
local function WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
Humanoid.Died:Connect(function()
local Module = script:FindFirstChild(DeathEquipped.Value)
if Module then
require(Module).PlayDeathEffect(Humanoid)
end
end)
end
local function SetupPlayer(Player)
local DeathEquipped = Instance.new("StringValue")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid", 300)
DeathEquipped.Parent = Player
DeathEquipped.Name = "DeathEquipped"
DeathEquipped.Value = "Ragdoll"
WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
Player.CharacterAdded:Connect(function(NewCharacter)
Character = NewCharacter
Humanoid = Character:WaitForChild("Humanoid", 300)
WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
end)
end
--------------------------------------------------
-- Signal Connections --
PlayerService.PlayerAdded:Connect(function(NewPlayer)
task.spawn(SetupPlayer, NewPlayer)
end)
I added the creation of the value in the script, with “Ragdoll” as a default death effect. Now you only have to change this value in server side when you click a button.
Script inside the GuiButton (Normal Script not a Local Script)
local Player = script:FindFirstAncestorWhichIsA("Player")
local DeathEquipped = Player:WaitForChild("DeathEquipped", 300)
script.Parent.MouseButton1Click:Connect(function()
DeathEquipped.Value = "Ragdoll"
end)
Edit: I lastly modified the above script, because I forgot something.
Never mind,I just rewrited the fade and Ragdoll script and everything works
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.