You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make a checkpoints script so that when the player touches the stage part it saves it as their death spawn to respawn -
What is the issue? Include screenshots / videos if possible!
the checkpoint only saves at the first checkpoint the player touches
The output error are Players.Diamondultra123.PlayerScripts.LocalScript:21: attempt to index nil with number
Also any possibles improvements to the script is appreciated
Module Script
local module = {}
function module.set(plr,arrow,stage,plrstage,stagenum,pressed)
if plrstage.Value < stagenum then
print(plrstage)
print(stagenum)
plrstage.Value = stagenum
print(plrstage)
print("this passed")
stage.CHECK.BrickColor = BrickColor.new("Lime green")
pressed = true
print(plr)
return {plr,stage,pressed}
end
end
--------------------------------------------------------
Local SCRIPT
local mod = require(game:GetService("ReplicatedStorage"):WaitForChild("ModuleScript"))
local plr = game.Players.LocalPlayer
local checkpointfolder = game.Workspace.Checkpoints
local pressed = false
local spawnpad = game.Workspace.SpawnLocation
for i, v in pairs(checkpointfolder:GetChildren()) do
v.Touched:Connect(function(hit)
print("this got touched")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local plrstage = player.leaderstats:WaitForChild("Stage")
local stage = v
local arrow = game.Workspace.Arrow
local stagenum = v.Value.Value
plr.RespawnLocation = spawnpad
local data = mod.set(player,arrow,stage,plrstage,stagenum,pressed)
print(data[2]:GetChildren())
if data[2].Value.Value == data[1]:WaitForChild("leaderstats").Stage.Value then
spawnpad.Position = data[2].Position + Vector3.new(0,.3,0)
data[1].CharacterAdded:Connect(function(char)
char:MoveTo(data[2].Position)
repeat task.wait()
until char ~= nil
print(data[2])
print(char.PrimaryPart.Position)
char:MoveTo(data[2].Position)
pressed = false
end)
end
end)
end