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

Hello! Why doesn't this prestige script work for my obby?

Hello! I'm making an obby and new to scripting, I have a script that should increase the player's prestige by 1 and reset the player's stage to 0, however, it doesn't work and I don't know why.

Prestige Script:

local Prestige = workspace.PrestigeTest

Prestige.Touched:Connect(function(touch)
	local humanoid 
	local player = game.Players:GetPlayerFromCharacter(touch.Parent)
	if touch.Parent:FindFirstChild("Humanoid") then
		humanoid = touch.Parent.Humanoid
	end
	
	if touch.Parent and touch.Parent.Parent:FindFirstChild("Humanoid") then
		humanoid = touch.Parent.Humanoid
	end
	
	if humanoid and player then
		if player.leaderstats.Stage.Value == 10 then
			player.leaderstats.Prestige.Value = player.leaderstats.Prestige.Value + 1
			player.leaderstats.Stage.Value = 0
		end
	end
end)

It might have something to do with my saving script because the leaderboard stats are all saved to a datastore.

Saving Script:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData")


local function SavePlayerData(player)
	
	local success,errormsg = pcall(function()
	
		local SaveData = {}
		
		for i,stats in pairs(player.leaderstats:GetChildren()) do
			
			SaveData[stats.Name] = stats.Value
		end	
		SaveDataStore:SetAsync(player.UserId,SaveData)
	end)
	
	if not success then 
		return errormsg
	end			
end	


Players.PlayerAdded:Connect(function(player)
	
	local Stats = Instance.new("Folder")
	Stats.Name = "leaderstats"
	Stats.Parent = player
	
	local Stage = Instance.new("StringValue")
	Stage.Name = "Stage"
	Stage.Parent = Stats
	Stage.Value = 0
	
	local Total = Instance.new("StringValue")
	Total.Name = "Total"
	Total.Parent = Stats
	Total.Value = 0
	
	local Prestige = Instance.new("StringValue")
	Prestige.Name = "Prestige"
	Prestige.Parent = Stats
	Prestige.Value = 0
	
	local Data = SaveDataStore:GetAsync(player.UserId)
	
	if Data then
			
		print(Data.Stage)
		
		for i,stats in pairs(Stats:GetChildren()) do
			
			stats.Value = Data[stats.Name]		
		end			
	else		
		print(player.Name .. " has no data.")			
	end
	
	
	player.CharacterAdded:Connect(function(character)
		
		local Humanoid = character:WaitForChild("Humanoid")
		local Torso = character:WaitForChild("HumanoidRootPart")
		
		wait()
		
		if Torso and Humanoid then
			if Stage.Value ~= 0 then
				
				local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
				Torso.CFrame = StagePart.CFrame + Vector3.new(0,1,0)					
			end	
		end	
	end)		
end)


Players.PlayerRemoving:Connect(function(player)
	
	local errormsg = SavePlayerData(player)
	
	if errormsg then	
		warn(errormsg)		
	end	
end)

game:BindToClose(function()
	for i,player in pairs(Players:GetPlayers()) do	
		
		local errormsg = SavePlayerData(player)
		if errormsg then
			warn(errormsg)
		end			
	end
	wait(2)	
end)

2 comments

0

Are there any errors in output?

0

No.

1 answer

✓ Accepted answer

It could be because your prestige and stage objects are StringValues, meant for words and text. Try making them IntValues instead

2 comments

0

This is correct. Make it Intvalues and it should work.

0

Thank you! This works!

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