3

I'm wondering if there's a way to run a command when someone joins a Single player world, I'm a upcoming map maker and I making my first map, I have lots of experience with Redstone but never got this far before. Currently I have different modes like: Extreme Mode, Easy Mode.

Back to the point, I need to know this because I want the player to get teleported when they join, Essentially if the player played before, And is 'far' into the map to go back to the start. I'm also making the map fully customizable with the ability to make the player die when they touch a certain block, And get their spawn point set when they touch another certain block.

4
  • 11
    Does this answer your question? Run command whenever someone joins a Minecraft server
    – Oast
    Commented Dec 6, 2021 at 15:11
  • 2
    I suggest you take our tour to understand how things work here. The whole site is moderated by trusted users.
    – pinckerman
    Commented Dec 6, 2021 at 15:13
  • 1
    Oast that doesn't work, I've tried it before and all it did was continue to teleport me to the location I have specified. I did ALL of them
    – 8572
    Commented Dec 7, 2021 at 19:32
  • 4
    @8572 If the answers in the linked duplicate don't work for you (and you're still seeking answers), then we would like you to edit to show what you've tried and what is happening instead. Otherwise this question will be closed as duplicate.
    – One 2 Many
    Commented Mar 1, 2022 at 7:05

1 Answer 1

1

I know one way of doing this. It might not be the most optimal but it works really well.

First make a scoreboard that count's all players in the game.

scoreboard objectives add PlayerCount dummy

Now make a second scoreboard to check if they logged in or not

scoreboard objectives add LoginTP dummy

Add the fake player past to 'PlayerCount'

scoreboard players add past PlayerCount 0

Now count the number of players and put that number into a score

execute store result score new PlayerCount run execute if entity @a

execute store result score new PlayerCount tells the code to put the number into the fake layer 'new' in the 'PlayerCount' scoreboard

run execute if entity @a count the number of players

This puts the number of players currently in the game into the scoreboard new


Now add all players to the 'LoginTP' scoreboard

scoreboard players add @a LoginTP 0

Now activate a tp command every time the number of players changes

execute unless score new PlayerCount = past PlayerCount run tp @a[scores={LoginTP=0}] ~ ~ ~

execute unless score new PlayerCount = past PlayerCount checks if the past amount of players and 'new' amount of players are different

run tp @a[scores={LoginTP=0}] ~ ~ ~ if the scores are different this command runs

@a[scores={LoginTP=0}] makes sure that the only ones with a score of 0 for 'LoginTP get teleported


Now you have to reset LoginTp every time the number of players changes

First delete the score whenever the player count changes

execute unless score new PlayerCount = past PlayerCount run scoreboard objectives remove LoginTP

And afterward, add the scoreboard back in again

scoreboard objectives add LoginTP dummy

And set all players in the world's score to 1

scoreboard players set @a LoginTP 1

Finally fix the PlayerCount

execute as @s run scoreboard players operation new PlayerCount = past PlayerCount

I highly recommend putting all these commands inside a single chain of repeating command blocks.

It would even be better if this is in a data pack.

Be sure these commands are always repeating and in order.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .