#script doesnt work

1 messages · Page 1 of 1 (latest)

normal wagon
#

hi guys well i tried an script for a part to be a spawnlocation when i use proximityprompt but it doesnt work

this is the script:

#

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

local checkpointStore = DataStoreService:GetDataStore("CheckpointStore")
local checkpointPart = workspace:FindFirstChild("TPSpawn")

-- Cria ProximityPrompt na parte, se não existir
local prompt = checkpointPart:FindFirstChildOfClass("ProximityPrompt")
if not prompt then
prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Salvar Checkpoint"
prompt.ObjectText = "Checkpoint"
prompt.HoldDuration = 0 -- ativar com um toque simples
prompt.Parent = checkpointPart
end

-- Debounce para evitar múltiplos salvamentos rápidos
local debounce = {}

prompt.Triggered:Connect(function(player)
if debounce[player.UserId] then return end
debounce[player.UserId] = true

local character = player.Character
if character then
    local root = character:FindFirstChild("HumanoidRootPart")
    if root then
        local pos = root.Position
        local data = {X = pos.X, Y = pos.Y, Z = pos.Z}

        local success, err = pcall(function()
            checkpointStore:SetAsync(tostring(player.UserId), data)
        end)

        if success then
            print("Checkpoint salvo para "..player.Name)
            -- Set TPSpawn as the player's respawn location
            player.SpawnLocation = checkpointPart
        else
            warn("Erro ao salvar checkpoint:", err)
        end
    end
end

task.wait(5) -- tempo para evitar spam
debounce[player.UserId] = false

end)

Players.PlayerAdded:Connect(function(player)
local success, data = pcall(function()
return checkpointStore:GetAsync(tostring(player.UserId))
end)

if success and data then
    local pos = Vector3.new(data.X, data.Y, data.Z)
    -- Set TPSpawn as the player's respawn location
    player.SpawnLocation = checkpointPart - first part of script
#

-- Teleport player to their checkpoint position on spawn
player.CharacterAdded:Connect(function(character)
local root = character:WaitForChild("HumanoidRootPart", 5)
if root then
root.CFrame = CFrame.new(pos)
~~ end~~
end)

    print("Checkpoint carregado para "..player.Name)
else
    -- If no checkpoint, clear RespawnLocation
    player.SpawnLocation = nil
    if not success then
        warn("Erro ao carregar checkpoint:", data)
    end
end

end) - second part of script

#

i mean i didnt put second part or first part in the script of course bhut i just dont know what to do

sharp basin
#

Ask ChatGPT again

normal wagon
normal wagon
normal wagon
sharp basin
#

ok

normal wagon
#

anyone?

topaz aurora
topaz aurora
normal wagon
# topaz aurora ChatGPT done goofed, ask it again.

i didnt use chatgpt bro, i used the roblox ia, i can understand scripts the real problem is i dont know how to use the scripts, ive already learned about everything dude, variables, functions, etc, i just cant write this shit bro, this pmo

#

tutorials aint explaining shit

#

my brain weak bro, i cant understand what should i write next to make some real code bro.

#

there are some words that i need to use that i dont understand bro, no one mentions that words bro

#

these guides dont mention about findfirstchild and some other things, i can read and compreheend everything i n the script i just dont know what is wrong dude, cuz the analysis dont say shit bro.

sharp basin
normal wagon
#

for example this part: player.SpawnLocation = checkpointPart
else
warn("Erro ao salvar checkpoint:", err)
end
end
end

#

how would i know that else comes 2 letters before warn?

#

or this part: if success and data then
local pos = Vector3.new(data.X, data.Y, data.Z)
-- Set TPSpawn as the player's respawn location
player.SpawnLocation = checkpointPart - first part of script

#

how would i know that local pos comes a litlle more spaced than above

sharp basin
normal wagon
#

basically the error didnt change anything

#

fixing the error didnt make the script work