Trying to invoke Remote functions breaks script

  1. What do you want to achieve?
    I am trying to make that if “person” is in top3 on leaderboard it gives to that person name tag above head

  2. What is the issue?
    Script breaks when I define Remote functions
    (printing only number 1,2 in script below!)

  3. What solutions have you tried so far?
    Printing

Script in workspace inside of Leaderboard:

local ds = game:GetService("DataStoreService")

local blocksODS = ds:GetOrderedDataStore("BlocksStats")

local timeUntilReset = 10


while wait(1) do
	
	
	timeUntilReset = timeUntilReset - 1
	
	script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
	
	
	if timeUntilReset == 0 then
		
		timeUntilReset = 10
	

		for i, plr in pairs(game.Players:GetPlayers()) do
			
			blocksODS:SetAsync(plr.UserId, plr.leaderstats.ExampleValue.Value)
		end
		
		for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
			
			if leaderboardRank.ClassName == "Frame" then
				leaderboardRank:Destroy()
			end
		end
		
		
		local success, errorMsg = pcall(function()
			
			local data = blocksODS:GetSortedAsync(false, 50)
			local blocksPage = data:GetCurrentPage()
			
			for rankInLB, dataStored in ipairs(blocksPage) do
				print("1")
				
				local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
				local blocks = dataStored.value
				local lbtext = game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.Text
				print("2")
				---Add invokers---
				local RebirthPos1 = game.ReplicatedStorage.LbPosFolder.Pos1:InvokeServer()
				local RebirthPos2 = game.ReplicatedStorage.LbPosFolder.Pos2:InvokeServer()
				local RebirthPos3 = game.ReplicatedStorage.LbPosFolder.Pos3:InvokeServer()
				---Add invokers--
				print("3")
				---Remove Invokers---
				local RebirthPos1Rem = game.ReplicatedStorage.LbPosFolder.Pos1Rem:InvokeServer()
				local RebirthPos2Rem = game.ReplicatedStorage.LbPosFolder.Pos2Rem:InvokeServer()
				local RebirthPos3Rem = game.ReplicatedStorage.LbPosFolder.Pos3Rem:InvokeServer()
				---Remove Invokers---
				print("4")
				local template = script.Template:Clone()
				
				print("5")
				template.Name = name .. "Leaderboard"
				
				template.PlrName.Text = name
				
				template.Rank.Text = "#" .. rankInLB
				print("6")
				if rankInLB == 1 then
					RebirthPos1 = true
					print("invoked")
					game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.Text = "#"..rankInLB.." ExampleValue"
					game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.TextColor3 = Color3.fromRGB(255, 255, 0)
				elseif rankInLB > 1 then
					RebirthPos1Rem = true
				elseif rankInLB == 2 then
					RebirthPos2 = true
					game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.Text = "#"..rankInLB.." ExampleValue"
					game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.TextColor3 = Color3.fromRGB(148, 148, 148)
				elseif rankInLB > 2 then
					RebirthPos2Rem = true
				elseif rankInLB == 3 then
					RebirthPos3 = true
					game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.Text = "#"..rankInLB.." ExampleValue"
					game.Workspace:WaitForChild(name).Head.NameTag.LeaderboardText.TextColor3 = Color3.fromRGB(83, 41, 0)
				elseif rankInLB > 3 then
					RebirthPos3Rem = true
				end
				template.Blocks.Text = blocks
				
				template.Parent = script.Parent	
			end			
		end)
	end
end

Script inside: ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")

function Pos1(player)

game.Players.Bool.Pos1.Value = true

end

game.ReplicatedStorage.LbPosFolder.Pos1.OnServerInvoke = Pos1

function Pos2(player)

game.Players.Bool.Pos2.Value = true

end

game.ReplicatedStorage.LbPosFolder.Pos2.OnServerInvoke = Pos2

function Pos3(player)

game.Players.Bool.Pos3.Value = true

end

game.ReplicatedStorage.LbPosFolder.Pos3.OnServerInvoke = Pos3
1 Like

Breaks as in stops running?

RemoveFunctions only continue on the script that fired after something was returned, so on the ServerScript script add return before the end. Doesn’t have to have anything inside, just return will do

Oh ye stop running :D.
I’lltry it :slight_smile: thank you!

This is how the code inside serverscriptservice looks like now still doesnt working:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

function Pos1(player)
	if player.Bool.Pos1.Value == false then
	player.Bool.Pos1.Value = true
		return true
		end
	return false
end

game.ReplicatedStorage.LbPosFolder.Pos1.OnServerInvoke = Pos1

function Pos2(player)
	if player.Bool.Pos2.Value == false then
		player.Bool.Pos2.Value = true
		return true
	end
	return false
end

game.ReplicatedStorage.LbPosFolder.Pos2.OnServerInvoke = Pos2

function Pos3(player)
	if player.Bool.Pos3.Value == false then
		player.Bool.Pos3.Value = true
		return true
	end
	return false
end

game.ReplicatedStorage.LbPosFolder.Pos3.OnServerInvoke = Pos3

I’m missing something because from what you showed it should work.

But, with what you need to do you should use remoteEvents. Avoid using removeFunctions unless it’s more efficient, since you don’t need to give any value to the client, you can use remvoeevents.

Alright thank you :slight_smile: :confused:

Are you getting any errors? Also, have you made sure that you spelled the name of the RemoteFunction right and all that?

No Errors so far and yea everything’s spelled right.

The server is being invoked as well right?

Uhmm… what do you mean by that?

1 Like

You are listening for when the server is invoked. You need to invoke the server for the code to run then. You need to do this on a local script by the way. Here is an example:

game.ReplicatedStorage.LbPosFolder.Pos3:InvokeServer()

Oh thank you, this is the problem it is in script not local script!

1 Like

Glad that helped you :slight_smile:

1 Like