#Unable to TP to saved scoreboard location

1 messages · Page 1 of 1 (latest)

icy token
#

tp @s ${Xcord}?

cobalt portal
#

it could be my getScore function

#

export function getScore(target, objective) {
target = target.name ?? (target.id ?? target)
const OBJ = world.scoreboard.getObjective(objective)
const PTS = OBJ?.getParticipants()
if (!PTS?.length) return 0
for ( let i= PTS.length; --i>-1;) {
const t = PTS[i]
if (t.displayName!==target) continue;
return OBJ.getScore(t);
} return 0
}

icy token
#

so something like

const Xcord = (getScore(player, 'XCord'))
const Ycord = (getScore(player, 'YCord'))
const Zcord = (getScore(player, 'ZCord'))

//then
player.teleport(`${Xcord}`)
//or
player.runCommandAsync(`tp @s ${Xcord} ${Ycord} ${Zcord}`)
#

im not sure how .teleport works

#

😭

#

or

cobalt portal
#

it seems to be a weird getScore function i just something basic lol

icy token
#

swap player and the scoreboard locations

#

your using a diff getscore than i do

#
function getScore(player, objective) {
  try {
    return world.scoreboard.getObjective(objective).getScore(player.scoreboard);
  } 
  catch (error) {
    return 0;
  }
}

is what i use

cobalt portal
#

awh ok let me try

#

it doesn't show any errors but my teleport just doesn't work in game

#

its not all that i need, i have some functions working with this

#

my timer is in my functions

#

the ability works that i made, just not going back to location

icy token
#
function saveCordsToScoreBoard(player) {
  player.runCommandAsync(`scoreboard players set @s XCord ${Math.floor(player.location.x)}`)
  player.runCommandAsync(`scoreboard players set @s YCord ${Math.floor(player.location.y)}`)
  player.runCommandAsync(`scoreboard players set @s ZCord ${Math.floor(player.location.z)}`)
}```
put this under the getScore function
#

wait

#

anywhere where getScore is

cobalt portal
#

maybe i need to make an if statement?

icy token
#

you need to filp the player and the score

cobalt portal
#

proper one, im using the filters in the command

#

oh?

icy token
#

with the getScore i just sent you it should look like

getScore(player, 'scoreName')
cobalt portal
#

doesn't make a difference after switching it around

#

still works the same

#

oh wait

#

lol

#

i figured it out, it was that my script wasn't reading the filter in the command quick enough... so i just had to drop it 1ms

#

let me show you

#

player.runCommandAsync(tp @s[scores={sgm=39..}] ${XCord} ${YCord} ${ZCord})

#

i had it at sgm=40

#

at 40 it switches back to 0

#

this works perfectly!!!

#

thank you for helping

#

@icy token

#

also think my getscore was bad, so yours helped as well

clever remnant
#

@cobalt portal do i close it now ?