How do I script this chain on a player upon dying?

https://i.gyazo.com/1f08b0312ecd99b947bf7089ff5df6b2.mp4
image image

So I have this stringValue attached to the player indicating that upon dying to the car, the player’s value changes from Human to Soul. I made this script that attaches a chain onto a person if their race value is a Soul. But the script doesn’t work. Please help, thanks

local Race = game.Players.LocalPlayer.PlayerValues.Race.Value
if Race == "Soul" then
	

	local Chains = game.ReplicatedStorage.Chains
	Chains.Parent = workspace
	Chains = CFrame.new(0.1,-1.6,1)
	
end
2 Likes

You should add a way to fire this function when the race changes.
You could do this;

game.Players.LocalPlayer.PlayerValues.Race.Changed:Connect(function() --Fires when the race changes
--Does stuff
end)

You can actually use the :GetPropertyChangedSignal() event.

For example:

local value = Instance.new("StringValue")
value.Value = "Hello"
wait(5)
value.Value = "World!"

value:GetPropertyChangedSignal("Value"):Connect(function()
    if value.Value == "World!" then
        print("Hello World!")
    end
end)

In your code:

local Race = game.Players.LocalPlayer.PlayerValues.Race

Race:GetPropertyChangedSignal("Value"):Connect(function() --Fires when it notices the "Value" property changed
    if Race.Value == "Soul" then --Checks if the value has changed to "Soul"
    	local Chains = game.ReplicatedStorage.Chains --Does the task
    	Chains.Parent = workspace
    	Chains = CFrame.new(0.1,-1.6,1)
    end
end)

Hope this came to your help.
-pranvexploder. :smiley:

1 Like

Thanks for the script. The script works but the chains wouldn’t properly CFrame onto the player. I don’t know why.
https://i.gyazo.com/09d723ec682333400fd0b056b5e28830.mp4
(I turned off the kill script for the car by the way)

image
Nevermind, I welded it together and its working fine