#Unable to TP to saved scoreboard location
1 messages · Page 1 of 1 (latest)
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
}
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
it seems to be a weird getScore function i just something basic lol
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
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
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
maybe i need to make an if statement?
you need to filp the player and the score
with the getScore i just sent you it should look like
getScore(player, 'scoreName')
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
@cobalt portal do i close it now ?