Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local checkpoints = {ItemType.CLAY_WHITE, ItemType.CLAY, ItemType.WOOL_BLUE}
- local checkpointshistory = {}
- local lastCheckedPositions = {}
- local function sendCheckpointMessage(player, message)
- MessageService.sendInfo(player, message)
- SoundService.playSoundForPlayer(player, SoundType.CAITLYN_CONTRACT_ACCEPT, player:getEntity():getPosition())
- end
- local function checkForPlayers()
- for _, blockType in pairs(checkpoints) do
- local blocks = BlockService.getAllBlocks({blockType})
- for _, block in pairs(blocks) do
- local blockPosition = block.position + Vector3.new(0, 3, 0)
- local nearbyPlayers = PlayerService.getNearbyPlayers(blockPosition, 5.4)
- if nearbyPlayers and #nearbyPlayers > 0 then
- for _, player in pairs(nearbyPlayers) do
- local found = false
- for _, history in pairs(checkpointshistory) do
- if history.playerId == player.userId then
- found = true
- if history.position ~= blockPosition then
- history.position = blockPosition
- sendCheckpointMessage(player, "Checkpoint saved")
- if lastCheckedPositions[player.userId] ~= tostring(blockPosition) then
- print("Player " .. player.name .. " is near block at position: " .. tostring(blockPosition))
- lastCheckedPositions[player.userId] = tostring(blockPosition)
- end
- end
- break
- end
- end
- if not found then
- table.insert(checkpointshistory, {playerId = player.userId, position = blockPosition})
- sendCheckpointMessage(player, "Checkpoint saved")
- print("Player " .. player.name .. " is near block at position: " .. tostring(blockPosition))
- lastCheckedPositions[player.userId] = tostring(blockPosition)
- end
- end
- end
- end
- end
- end
- Events.EntitySpawn(function(event)
- local entity = event.entity
- local player = entity:getPlayer()
- if player then
- for _, history in pairs(checkpointshistory) do
- if history.playerId == player.userId then
- local blockPosition = history.position
- local newPosition = blockPosition + Vector3.new(0, 5, 0)
- entity:setPosition(newPosition)
- break
- end
- end
- SoundService.playSoundForPlayer(player, SoundType.GOLD_SPIRIT_DAGGER_SLASH, entity:getPosition())
- end
- end)
- while task.wait(0.1) do
- checkForPlayers()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement