I've been trying to test one of my local scripts that adds velocity to that player's torso, but I needed a way to re - create it after the player dies. All the script is supposed to do is add the required velocity back to the player's torso when he or she re - spawns:
function PlayerDied()
print("began")
repeat wait() until player.Character.Humanoid.Health ~= 0
Body = Instance.new("BodyVelocity", player.Character.Torso)
Body.Velocity = Vector3.new(-24,0,0)
Body.MaxForce = Vector3.new(4000,0,4000)
print("done")
end
player.Character.Humanoid.Died:connect(PlayerDied)
The problem is, the function only runs once for when the player dies. The script is local and is located in the StarterPlayerScripts file. NOTE the script MUST be local (UserInputService). Please HALP!!! Thx!
--------------EDIT--------------
Here's the whole script that I'm running just in case there might be some conflicting info:
Var = 0
Var1 = 0
player = game.Players.LocalPlayer
print(player)
repeat wait() until player.Character ~= nil
Body = Instance.new("BodyVelocity", player.Character.Torso)
Body.Velocity = Vector3.new(-24,0,0)
Body.MaxForce = Vector3.new(4000,0,4000)
function PlayerDied()
print("began")
repeat wait() until player.Character.Humanoid.Health ~= 0
Body = Instance.new("BodyVelocity", player.Character.Torso)
Body.Velocity = Vector3.new(-24,0,0)
Body.MaxForce = Vector3.new(4000,0,4000)
print("done")
end
player.Character.Humanoid.Died:connect(PlayerDied)
game:GetService("UserInputService").InputBegan:connect(function(Key, Condition)
if player.Character.Humanoid.Health ~= 0 then
if Key.KeyCode == Enum.KeyCode.D then
Var = 1
if Var == 1 and Var1 == 1 then
Body.Velocity = Vector3.new(-24,0,0)
elseif Var == 1 then
Body.Velocity = Vector3.new(-24,0,-24)
end
end
if Key.KeyCode == Enum.KeyCode.A then
Var1 = 1
if Var == 1 and Var1 == 1 then
Body.Velocity = Vector3.new(-24,0,0)
elseif Var1 == 1 then
Body.Velocity = Vector3.new(-24,0,24)
end
end
end
end)
game:GetService("UserInputService").InputEnded:connect(function(Key, Condition)
if player.Character.Humanoid.Health ~= 0 then
if Key.KeyCode == Enum.KeyCode.D then
if Var == 1 and Var1 == 1 then
Body.Velocity = Vector3.new(-24,0,24)
Var = 0
elseif Var == 1 and Var1 == 0 then
Body.Velocity = Vector3.new(-24,0,0)
Var = 0
end
end
if Key.KeyCode == Enum.KeyCode.A then
if Var == 1 and Var1 == 1 then
Body.Velocity = Vector3.new(-24,0,-24)
Var1 = 0
elseif Var1 == 1 and Var == 0 then
Body.Velocity = Vector3.new(-24,0,0)
Var1 = 0
end
end
end
end)

6 comments
Actually... I'm sorry to say this but the script NEEDS to be local (UserInputService). Please edit your script to work around this. Sorry :/
Why does it NEED to be local? If that's the case, you can remove the PlayerAdded functions. But the Server Should be dealing with BodyObjects inside characters, not the client.
Your saying that you can use UserInputService inside a server - side script? If so, is this service part of a player instead of the game as a whole?
It specificly says this on the wiki: "The UserInputService is a service which is used to detect the type of input available on a user's device via the use of a LocalScript. It allows LocalScripts to perform different actions depending on the device used to provide the best experience for the end user" --Quote from http://wiki.roblox.com/index.php?title=API:Class/UserInputService
How was I to know that the script was utilizing UIS if you did not show any portion of the script that did utilize it, nor did you state it in your explanation? Like I said, just remove the PlayerAdded event.
Sorry about that bud. Though I'll accept your answer, but in the future when your answering questions only change the parts that need fixing. It gets REALLY annoying when people change your scripts up from local to server and vice - versa.