Script works on studio but not in the game

Hello I made a script that works on studio with no errors but doesnt work in-game.
Only the billboard gui clonning thing doesn’t work. Others working with no errors.

local datastoreservice = game:GetService("DataStoreService")
local data1 = datastoreservice:GetDataStore("data5")



local function DataStuff(Player)
	local NonUsingItemsFolder = Instance.new("Folder")
	NonUsingItemsFolder.Parent = Player
	NonUsingItemsFolder.Name = "NonUsingItemsFolder"

	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = Player
	leaderstats.Name = "leaderstats"



	local EnabledGive = Instance.new("BoolValue")
	EnabledGive.Parent = Player
	EnabledGive.Value = false
	EnabledGive.Name = "EnabledGive"





	local success, errormsg = pcall(function()

		local Crush_Points = Instance.new("IntValue",leaderstats)
		Crush_Points.Name = "Crush Points"
		Crush_Points.Value = data1:GetAsync(Player.UserId.."-Points",Crush_Points.Value) or 0


		local Top_Points = Instance.new("IntValue",leaderstats)
		Top_Points.Name = "Top Crush Points"
		Top_Points.Value = data1:GetAsync(Player.UserId.."-TopPoints",Top_Points.Value) or 0 

	end)

	if success then
		print("Successfully got data!")
	else
		print("Error: " .. errormsg)
		Player:Kick("Error getting data.")
	end




end

game.Players.PlayerAdded:Connect(function(Player)
	
	--  Crush Points
	-- Top Crush Points

	DataStuff(Player)
	
--local chr = Player.Character
		
		print("xd")

	local Billboard = game.ReplicatedStorage.Billboard.BillboardGui:Clone()
	
	for i,v in pairs(game.Workspace:GetChildren()) do
		print(Player.Name .. v.Name)
		if v.Name == Player.Name then
			print("clonning.")
			Billboard.Parent = v.Head
			print("done.")
		end
	end
		
		while true do
			wait(0.1)
			Billboard.TextLabel.Text = Player.leaderstats["Crush Points"].Value
			
		end
	end)
	



game.Players.PlayerRemoving:Connect(function(player)
print("Player left.")
	local success, err = pcall(function()
		data1:SetAsync(player.UserId.."-Points",player.leaderstats["Crush Points"].Value)
		data1:SetAsync(player.UserId.."-TopPoints",player.leaderstats["Top Crush Points"].Value)
	end)
	if success then
		print("Successfully saved "..player.Name.."'s Data!")
	else
		warn(err)
	end
end)



while true do
	wait(1)
	for i,v in pairs(game.Players:GetChildren()) do
		
	if v.EnabledGive.Value == true then
		v.leaderstats["Crush Points"].Value += 1
		
		if v.leaderstats["Top Crush Points"].Value <= v.leaderstats["Crush Points"].Value then
			
				v.leaderstats["Top Crush Points"].Value = v.leaderstats["Crush Points"].Value
				end
		end

	end
	
end





To which print is it printing?

Maybe try

player.CharacterAdded:Connect(function(char) 

And then clone the BillboardGui to char.Head

Have you enabled all things to do with APIs in Game Settings?

Character added event is not triggering without errors, already did that.

Yes, already did that.
3000000

1 Like

Can you show me the code again?

Have you just tried adding a print statement after the CharacterAdded event just to make sure it is firing?

you’re iterating through workspace to get the character, and changing the text every tenth of a second, replace it with this

game.Players.PlayerAdded:Connect(function(Player)

	--  Crush Points
	-- Top Crush Points


	--local chr = Player.Character

	
	local Billboard  --so we dont have to get the billboard from the players head each time
Player.CharacterAdded:Connect(function(char) --fires when the character spawns, its right below playeradded in case the character spawns after we do everything else
	 Billboard = game.ReplicatedStorage.Billboard.BillboardGui:Clone() --clones the billboard

		repeat wait() until char:FindFirstChild("Head") --waits for the head
		Billboard.Parent = char:FindFirstChild("Head") --puts the billboard in the head
		Billboard.TextLabel.Text = Player:WaitForChild("leaderstats")["Crush Points"].Value --changes the text to crush points' value

		
	end)
	DataStuff(Player) --does the data stuff
	Player:WaitForChild("leaderstats")["Crush Points"]:GetPropertyChangedSignal("Value"):Connect(function() --instead of looping every tenth of a second, why not do it when it changes
		if Billboard then --checks if the billboard exists
		Billboard.TextLabel.Text = Player:WaitForChild("leaderstats")["Crush Points"].Value --sets the billboards text to crush points
		end	
		end)
	

end)
2 Likes

IT WORKS! Thank you so much!
300000000