So I have this script where when the player’s value is a “Soul” then they have these chains welded on their character.
It works but the problem is that if the player resets or dies, then the weld disappears when they respawn. How can I keep the welds on the character? There’s 2 welds, chain1 and chain2. Thanks
local Race = game.Players.LocalPlayer.PlayerValues.Race
Race:GetPropertyChangedSignal("Value"):Connect(function()
if Race.Value == "Soul" then
local Chains = game.ReplicatedStorage.Chains.Handle
local Torso = game.Players.LocalPlayer.Character.UpperTorso
Chains.CFrame = Torso.CFrame * CFrame.new(0,0,-0.62)
local weld = Instance.new("Weld")
weld.Part0 = Torso
weld.Part1 = Chains
weld.C0 = Torso.CFrame:Inverse()
weld.C1 = Chains.CFrame:Inverse()
weld.Parent = Chains
local Chains2 = game.ReplicatedStorage.Chains.Handle2
local Torso = game.Players.LocalPlayer.Character.UpperTorso
Chains2.CFrame = Torso.CFrame * CFrame.new(0,-0.8,-0.71)
local weld2 = Instance.new("Weld")
weld2.Part0 = Torso
weld2.Part1 = Chains2
weld2.C0 = Torso.CFrame:Inverse()
weld2.C1 = Chains2.CFrame:Inverse()
weld2.Parent = Chains2
Chains.Parent = workspace
Chains2.Parent = workspace
end
end)
The value won’t change right after the player dies, so you’ll have to run the code outside of the event as well.
if Race.Value == "Soul" then
local Chains = game.ReplicatedStorage.Chains.Handle
local Torso = game.Players.LocalPlayer.Character.UpperTorso
Chains.CFrame = Torso.CFrame * CFrame.new(0,0,-0.62)
local weld = Instance.new("Weld")
weld.Part0 = Torso
weld.Part1 = Chains
weld.C0 = Torso.CFrame:Inverse()
weld.C1 = Chains.CFrame:Inverse()
weld.Parent = Chains
local Chains2 = game.ReplicatedStorage.Chains.Handle2
local Torso = game.Players.LocalPlayer.Character.UpperTorso
Chains2.CFrame = Torso.CFrame * CFrame.new(0,-0.8,-0.71)
local weld2 = Instance.new("Weld")
weld2.Part0 = Torso
weld2.Part1 = Chains2
weld2.C0 = Torso.CFrame:Inverse()
weld2.C1 = Chains2.CFrame:Inverse()
weld2.Parent = Chains2
Chains.Parent = workspace
Chains2.Parent = workspace
end
--Event after here
And if you’re worried that this’ll take up a lot of lines of code, make this into a function, and call it outside of the event, and in the event itself.
I thought the question was it wouldn’t weld together on the death, and your character wouldn’t weld together, anyways a simple solution is to make a character with it in starter character, or you can make the chain from the player.CharacterAdded event
How do I make a character with it in starter character, every player has their own assets and hats, how can I make a startercharacter that saves their avatar while retaining the weld?
I tried using character added but it seems to only work with server scripts so I can’t reference specifically if the player matches the stringvalue since thats for local scripts
You can use get player from character in the server script by doing
workspace.ChildAdded:Connect(function (char) if game.Players:GetPlayerFromCharacter(char) then
–check value, make weld instance.
end end)
If you need a local script, then make a remote event to talk to the server to create the instance using what you did.
Ok thanks, so now the script prints “Yes” after correcting ‘workplace’. But when I add to the script and add a line that checks if player value is human, it does not print “Yes” anymore.
All players spawn with the value of “Human” so I don’t see why now the script doesn’t print anything in the output.
I think its because this is a severscript and I can’t reference localplayer.
By putting your weld in a function, you can check if the value is equal to “Soul” when they respawn. Since this is a LocalScript and you want it to load every time the character respawns, you would put this inside of StarterCharacterScripts.
local Race = game.Players.LocalPlayer.PlayerValues.Race
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local function Weld()
local Chains = game.ReplicatedStorage.Chains.Handle
local Torso = Character.UpperTorso
Chains.CFrame = Torso.CFrame * CFrame.new(0,0,-0.62)
local weld = Instance.new("Weld")
weld.Part0 = Torso
weld.Part1 = Chains
weld.C0 = Torso.CFrame:Inverse()
weld.C1 = Chains.CFrame:Inverse()
weld.Parent = Chains
local Chains2 = game.ReplicatedStorage.Chains.Handle2
local Torso = Character.UpperTorso
Chains2.CFrame = Torso.CFrame * CFrame.new(0,-0.8,-0.71)
local weld2 = Instance.new("Weld")
weld2.Part0 = Torso
weld2.Part1 = Chains2
weld2.C0 = Torso.CFrame:Inverse()
weld2.C1 = Chains2.CFrame:Inverse()
weld2.Parent = Chains2
Chains.Parent = workspace
Chains2.Parent = workspace
end
if Race.Value == "Soul" then
Weld()
end
Race:GetPropertyChangedSignal("Value"):Connect(function()
if Race.Value == "Soul" then
Weld()
end
end)
FYI what @Alphexus said is in just a local script, so other players will not see the weld. Try doing what he did, but using a server script, and getting the character from script.Parent, and getting the player from game.players: GetPlayerFromCharacter (character)