I want to detect when the player respawns to change their walkspeed and add a sword to their backpack.
I can’t detect when the player respawns. I’ve been told “CharacterAdded” fires when a player respawns, but it will not fire under any circumstances. Humanoid.Died:Connect(function() will fire, however.
My god, what have I NOT tried would be an easier question. I’ve tried waiting after the player dies, using characteradded, using characteradded and checking if the player was there afterwards. nothing has worked.
Showing the script is a little pointless because none of it is related to the player respawning, but I’ll show where I want it to detect the player respawning.
if map.Name == "ClassicalDimension" then
task.wait(2)
write("Oh dear.. It appears you've teleported right into a swordfighting match..")
write("The only way to leave is to best yourself against your opponent!")
write("Also, don't worry about death. We've imbedded an immortality chip into your brain.")
write("Good luck!!!")
task.wait(0.25)
summon:FireServer()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
game.Players.LocalPlayer.Character.Humanoid.JumpHeight = 7
workspace:WaitForChild("ClassicalDimension", math.huge).ClassicalDMusic:Play()
--if the player dies then respawn with walkspeed and sword
end
Looks like you’re past this… Basic way to get the character on spawn/login.
-- ServerScript
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid") --load pause
print(character)
end)
end)
--ClientScript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") --load pause
print(character)
The player isn’t going to respawn … the character will.
CharacterAdded:Wait() will fire right when added … not if it’s already there. So you use:
local character = player.Character or player.CharacterAdded:Wait()
Once you’re at humanoid, that should be easy enough. As for sure now, everything is in place.
May also want to toss in:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local backpack = player:WaitForChild("Backpack")
print(character)
print(backpack)
Access to all you would need.
Do the same thing to locate and lock onto your items, for sure … then clone them over.
top down server script.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local backpack = player:WaitForChild("Backpack")
local sword = game.ServerStorage:WaitForChild("Sword")
humanoid.WalkSpeed = 25
humanoid.JumpPower = 50
local clone = sword:Clone()
clone.Parent = backpack
end)
end)
Everytime the player respawns this will run again.
Well, this thread in my script doesn’t happen as soon as you start the game. There’s a LOT of things that happen before it. Plus it’s in an if statement so I feel like theres more to it than just accessing them
It’s something else …
Is it a server script? is everything spelled right? Placement is key also… This need to not have any pasues leading up to it. Should be one of the 1st things done in the script. Getting the character.
If this is something used off a remote you would get the player.character from that.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local backpack = player:WaitForChild("Backpack")
local sword = game.ReplicatedStorage:WaitForChild("Sword")
-- Need to use ReplicatedStorage for local scripts.
humanoid.WalkSpeed = 25
humanoid.JumpPower = 50
local clone = sword:Clone()
clone.Parent = backpack
Okay, so the swords DO go into my backpack now, but not only is there 8 of them, none of them work. and even if they did work, this wouldn’t solve my main issue. I need these lines to run only when the player respawns after dying. Currently they run after it tells the background music to play.