Can someone tell me about the problem in this script?
local SpawnsFolder = game.Workspace.Spawns
for i, v in pairs(SpawnsFolder:GetChildren()) do
if v:IsA(“BasePart”) then
local previousTouched = {}
v.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Stages.Value < tonumber(v.Name) then
plr.leaderstats.Stages.Value = tonumber(v.Name)
end
if tonumber(v.Name) == 251 then
if not table.find(previousTouched, plr.Name, plr.UserId) then
table.insert(previousTouched, plr.UserId, plr.Name)
game:GetService('ReplicatedStorage').Message:FireAllClients(string.format('%s has completed the Obby!', plr.Name))
end
end
if math.fmod(plr.leaderstats.Stages.Value, 25) == 0 then
if not table.find(previousTouched, plr.Name, plr.UserId) then
table.insert(previousTouched, plr.UserId, plr.Name)
game:GetService('ReplicatedStorage').Message:FireAllClients(string.format('Congratulations to %s for reaching stage %s!', plr.Name, v.Name))
end
end
end)
end
function firstDeath(plr)
local humanoid = plr.Character:WaitForChild(“Humanoid”)
humanoid.Died:Connect(function()
task.wait(0.3)
–local deathCount = plr.leaderstats.Deaths
–deathCount.Value = deathCount.Value + 1
plr:LoadCharacter()
respawnPlayer(plr)
end)
end
function respawnPlayer(plr)
repeat task.wait() until plr.Character
repeat task.wait() until plr.Character:FindFirstChild(“HumanoidRootPart”)
local humanoidrootpart = plr.Character:FindFirstChild(“HumanoidRootPart”)
local currentSpawn = workspace.Spawns[plr.leaderstats.Stages.Value]
humanoidrootpart.CFrame = CFrame.new(currentSpawn.CFrame.X, currentSpawn.CFrame.Y + 5, currentSpawn.CFrame.Z)
end
Pretty sure you’re trying to call functions that don’t exist yet. firstDeath and respawnPlayer should probably be defined somewhere BEFORE you attempt to call them, not AFTER you attempt to call them.
module.deathEvents = function(plr)
firstDeath(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:FindFirstChild(“Humanoid”)
humanoid.Died:Connect(function()
wait(0.3)
–local deathCount = plr.leaderstats.Deaths
–deathCount.Value = deathCount.Value + 1
plr:LoadCharacter()
respawnPlayer(plr)
end)
end)
end
function firstDeath(plr)
local humanoid = plr.Character:WaitForChild(“Humanoid”)
humanoid.Died:Connect(function()
task.wait(0.3)
–local deathCount = plr.leaderstats.Deaths
–deathCount.Value = deathCount.Value + 1
plr:LoadCharacter()
respawnPlayer(plr)
end)
end
function respawnPlayer(plr)
repeat task.wait() until plr.Character
repeat task.wait() until plr.Character:FindFirstChild(“HumanoidRootPart”)
local humanoidrootpart = plr.Character:FindFirstChild(“HumanoidRootPart”)
local currentSpawn = workspace.Spawns[plr.leaderstats.Stages.Value]
humanoidrootpart.CFrame = CFrame.new(currentSpawn.CFrame.X, currentSpawn.CFrame.Y + 5, currentSpawn.CFrame.Z)
end
module.stats = function(plr,config)
local leaderstats = Instance.new(“Folder”)
local stages = Instance.new(“IntValue”)
–local deaths = Instance.new(“IntValue”)
local FirstSpawn = Workspace.Spawns[‘1’]
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
stages.Parent = leaderstats
stages.Name = "Stages"
--deaths.Parent = leaderstats
--deaths.Name = "Deaths"
stages.Value = 1
--deaths.Value = 0
local skips = Instance.new("IntValue")
skips.Name = "Skips"
skips.Parent = plr
skips.Value = 1
unlimSkips(skips,plr,config)
wait(1)
respawnPlayer(plr)
end