Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[FIXED]What's wrong with my Script?[FIXED}

So here's the tree pointing to the location of the script if helpful: ==Workspace== ==Automated== -Game(Script)- ==Automated== ==Workspace== Here's the script's code:

--[[Variables]]--
local respawnTime = 1
local ds = game:GetService("DataStoreService"):GetDataStore("Stage")
local Players = game:GetService("Players")
Players.CharacterAutoLoads = false
--[[Variables]]--

--[[Game Handling]]--
Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character)
		--[[Variables]]--
		Humanoid = Character:FindFirstChild("Humanoid")
		--[[Variables]]--
		
		--[[Leaderstats]]--
		local leaderstats = Instance.new("Model", Player)
 		leaderstats.Name = "leaderstats"

		local stage = Instance.new("IntValue", leaderstats)
		stage.Name = "Stage"
		stage.Value = ds:GetAsync(Player.Name) or 1
		
		local tim = Instance.new("IntValue", leaderstats)
		tim.Name = "Time"
		tim.Value = 0
		
		--[[=Thread with the time Stat=
		local Time = coroutine.wrap(function()
			tim.Value = tim.Value + 1
		end)
		]]--
		--[[=Thread with the time Stat=]]--
		
		--[[Leaderstats]]--
		
		--[[Respawn Handling]]--
		if Humanoid then
			Humanoid.Died:connect(function()
				wait(respawnTime)
				Player:LoadCharacter()
				
				if Player.leaderstats.Stage.Value == 1 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["1"].Position)
				elseif Player.leaderstats.Stage.Value == 2 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["2"].Position)
				elseif Player.leaderstats.Stage.Value == 3 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["3"].Position)
				elseif Player.leaderstats.Stage.Value == 4 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["4"].Position)
				elseif Player.leaderstats.Stage.Value == 5 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["5"].Position)
				elseif Player.leaderstats.Stage.Value == 6 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["6"].Position)
				elseif Player.leaderstats.Stage.Value == 7 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["7"].Position)
				elseif Player.leaderstats.Stage.Value == 8 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["8"].Position)
				elseif Player.leaderstats.Stage.Value == 9 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["9"].Position)
				elseif Player.leaderstats.Stage.Value == 10 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["10"].Position)
				elseif Player.leaderstats.Stage.Value == 11 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["11"].Position)
				elseif Player.leaderstats.Stage.Value == 12 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["12"].Position)
				elseif Player.leaderstats.Stage.Value == 13 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["13"].Position)
				elseif Player.leaderstats.Stage.Value == 14 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["14"].Position)
				elseif Player.leaderstats.Stage.Value == 15 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["15"].Position)
				elseif Player.leaderstats.Stage.Value == 16 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["16"].Position)
				elseif Player.leaderstats.Stage.Value == 17 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["17"].Position)
				elseif Player.leaderstats.Stage.Value == 18 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["18"].Position)
				elseif Player.leaderstats.Stage.Value == 19 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["19"].Position)
				elseif Player.leaderstats.Stage.Value == 20 then
					Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["20"].Position)
				end
			end)
		end
		--[[Respawn Handling]]--
	end)
 	--Loads the Character for the first time!
	Player:LoadCharacter()
end)
--[[Game Handling]]--

--[[Leaderstats]]--
Players.PlayerRemoving:connect(function(Player)
    ds:UpdateAsync(Player.Name, function(oldValue) return Player.leaderstats.Stage.Value end)
end)

game.OnClose = function()
    for i,v in pairs(Players:GetChildren()) do
        ds:UpdateAsync(v.Name, function(oldValue) return v.leaderstats.Stage.Value end)
    end
    wait(1)
end
--[[Leaderstats]]--

I think the problem is on line 23 to 25. When I test the game(I know the DataStore won't work), I get the Stage(IntValue) in my leaderstats. Now instead of seeing Time, I see Value(IntValue) on the next one.

Pls help me, I'm an intermediate scripter that needs help!!!

1 answer

✓ Accepted answer

Ill show you how you can fix it, first of all, lines 38-84, Instead of putting

 if Player.leaderstats.Stage.Value == 1 then
                    Humanoid.Parent:MoveTo(workspace.Obstacles.Checkpoints["1"]
if Player.leaderstats.Stage.Value == 1 then
Player:GetCharacter().Torso.CFrame = CFrame.new(workspace.Obstacles.CheckPoints["1"]:GetModelCFrame())

Use this method to move the player^

3 comments

0

I'm going to try

0

My MoveTo method used to work but now it doesnt. My old method was to get the CFrame of the torso and teleport the character to the postion of the level which had the nice little jump animation if you try it.

0

I fixed it! I examined your code then realized what happened! Thx!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.