Hi! My name is Twisted, I’m making a little introduction about myself since this is my first topic post ever! I’m really excited to ask you guys questions and tell you everything I’ve tried and have done. A few welcomes would be very appreciated! Anyway… let’s get to the point.
I’m currently making a running game, but I’m not sure how to make my character respawn where I died. I’m new to scripting so I don’t know too much about things that are simple but I’m learning and getting better each day. So a bit of help where I could find where to do it or a script so I can visualize how to do it would be very helpful!
I haven’t attempted to make this since I couldn’t find a source to learn/see how to do it.
That was meant to ben pseudocode, not a fully working script. you seem to be new to scripting I encourage you learn basics like variables and the data types of Lua before making a project.
game.Players.PlayerAdded:Connect(function(Player)
-- This function will run whenever someone new joins the game.
Player.CharacterAdded:Connect(function(Character)
--This function will run whenever that player's character spawns.
Character.Humanoid.Died:Connect(function()
-- This function will run whenever that player's character's humanoid dies
local PositionWhenDied = Character.Torso.Position
Player.CharacterAdded:Wait() -- Wait for the new character to spawn.
Player.Character:MoveTo(PositionWhenDied) --Move the character to the old position
end)
end)
end)
You can copy and paste this into a script in workspace or ServerScriptService or wherever.
game.Players.PlayerAdded:Connect(function(player)
local spawn_point
player.CharacterAdded:Connect(function(char)
if spawn_point then
char:MoveTo(spawn_point)
end
char:WaitForChild("Humanoid").Died:Connect(function()
spawn_point = char.HumanoidRootPart.Position
end)
end)
end)
It didn’t work, I’m not sure what the problem is but I did realize the script goes away when I test the game. Does that happen naturally in Roblox Studio?
I have, and the tutorials are great! But, the good tutorial episodes weren’t coming out often so I stopped watching Alvin. Thanks for telling me though! ^^
If you put it in ServerScriptService, that’d make sense, as that service is only accessible for the server, and by default in Studio test mode you’re in client-mode.
Do you get any errors? I really think I wrote the correct logic
I’m not sure exactly about the code, but I think if it’s like a running game, and there’s possibly levels? I think if you created a spawn, and then added it to a team, so let’s say I died in “The Desert”, I would respawn where the spawn for “The Desert” is because I had a check point there. I’m not sure about the coding for it, so you should watch AlvinBlox’s coding channel and watch videos of where he is scripting spawns for different teams. Sorry if I wasn’t of much help.
Well, maybe try searching up tutorials for different concepts on YouTube to learn more about them, like events, functions, while loops, for loops, and if/then statements, that’s how I started. Also, try out my suggestion up above, that should work.
I saw an AlvinBlox video about what you just explained but that’s not what I’m going for. I need my character to spawn exactly where they die. Thanks for the help though!
@C_Sharper The script goes away whenever I test the script.
@C0lvy123 Sadly, the script didn’t work that you gave me.
Ah, so like if I died in the water, you’d want me to spawn exactly where I died. Hm, this is a bit tricky, I’m not sure if any other developer has ever done this before, but I think to do this, you’d have to be an advanced scripter. I suggest maybe learning from someone who knows Lua or Java as they’re both easy to learn. I might be able to help later on, but for now I think you may have to take some classes if you can.
Edit: Do you mean when they die it’s like a checkpoint? Sorry I’m confused, if they were to respawn where they died, they would just die for the whole duration of their time spent in-game.
Oh, you have to go to drafts and click commit next to the script. Then playtest and my script should work. You can find drafts in the view tab, then right click the script you want and “commit” should pop up.