Workspace.Techy's Obby System.Configurations.Main:302: FireServer can only be called from the client

Hello everyone!.I am need Solution. I am have error is in output.Techy’s Obby System.Configurations.Main:302: FireServer can only be called from the client. I am use Techy’s Obby System for it. This is the last line of the code.Main script is Normal script.This folder in Workspace.Also here Location of this:
Location of all scripts

Main Script:

local settings = require(script.Parent)
local ws = game:GetService("Workspace")
local sss = game:GetService("ServerScriptService")
local sg = game:GetService("StarterGui")
local rst = game:GetService("ReplicatedStorage")
local sp = game:GetService("StarterPlayer")

------
local event = Instance.new("RemoteEvent", rst)
event.Name = "ChangeStageByTechy"
------

local function SavingScript()
	local script = Instance.new('Script', game.ServerScriptService)
	script.Name = "SavingScript"

	local Players = game:GetService("Players")
	local DataStoreService = game:GetService("DataStoreService")
	local SaveDataStore = DataStoreService:GetDataStore(settings.datastoreName)

	local function SavePlayerData(player)
		if settings.dataAutosaves then

			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
	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 = 1

		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	
		elseif not settings.dataAutosaves then
			print("Autosave is Disabled.")

			player.leaderstats.Stage.Value = 1
		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)
					character:MoveTo(StagePart.Position)				
				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)
end
--------

local function StageScript()
	local script = Instance.new('Script', game.ServerScriptService)
	script.Name = "StageScript"

	local Stages = workspace:WaitForChild("Stages")

	for i,Stage in pairs(Stages:GetChildren()) do

		Stage.Touched:Connect(function(touch)

			local humanoid

			if touch.Parent:FindFirstChild("Humanoid") then

				humanoid = touch.Parent.Humanoid
			end

			if touch.Parent and touch.Parent.Parent:FindFirstChild("Humanoid") then

				humanoid = touch.Parent.Parent.Humanoid
			end

			if humanoid then

				local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)

				local PlayerStage = player.leaderstats.Stage.Value

				if tonumber(Stage.Name) == PlayerStage + 1 then

					player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1

				elseif tonumber(Stage.Name) > PlayerStage + 1 then

					humanoid.Health = 0
				end
			end
		end)
	end
end

---------------
local function StageTransfer()

	local script = Instance.new('Script', game.ServerScriptService)
	script.Name = "StageTransfer"

	game:GetService("ReplicatedStorage").ChangeStageByTechy.OnServerEvent:Connect(function(player, direction, target)
		local char = game.Workspace:FindFirstChild(player.Name)

		local function teleport()
			local cp = game.Workspace.Stages:FindFirstChild(tostring(player.TeleportedStage.Value))
			local cpp = cp.Position

			char:MoveTo(cpp)
		end


		if direction == "up" then
			--
			player.TeleportedStage.Value = player.TeleportedStage.Value + 1

			if tonumber(player.TeleportedStage.Value) > tonumber(player.leaderstats.Stage.Value) then
				player.TeleportedStage.Value = 1
			end

			teleport()
			--
		elseif direction == "down" then
			player.TeleportedStage.Value = player.TeleportedStage.Value - 1

			if tonumber(player.TeleportedStage.Value) < 1 then
				player.TeleportedStage.Value = player.leaderstats.Stage.Value
			end

			teleport()

		elseif direction == "up2" then
			player.TeleportedStage.Value = player.TeleportedStage.Value + 10

			if tonumber(player.TeleportedStage.Value) > tonumber(player.leaderstats.Stage.Value) then
				player.TeleportedStage.Value = 1
			end

			teleport()
		elseif direction == "down2" then
			player.TeleportedStage.Value = player.TeleportedStage.Value - 10

			if tonumber(player.TeleportedStage.Value) < 1 then
				player.TeleportedStage.Value = player.leaderstats.Stage.Value
			end

			teleport()

		elseif direction == "lobby" then
			player.TeleportedStage.Value = 1		
			teleport()

		elseif direction == "lc" then
			player.TeleportedStage.Value = player.leaderstats.Stage.Value		
			teleport()
		elseif direction == "set" then
			player.TeleportedStage.Value = player.leaderstats.Stage.Value		
			teleport()
		elseif direction == "goto" then
			player.TeleportedStage.Value = target
			teleport()
		end

		if direction == "joined" then
			if settings.dataAutosaves then
				player.TeleportedStage.Value = player.leaderstats.Stage.Value
				teleport()
				print("Moved ".. player.Name.. " to their last stage." )
			end
		elseif direction == "respawned" then
			teleport()
		elseif direction == "respawned2" then
			player.TeleportedStage.Value = player.leaderstats.Stage.Value
		elseif direction == "Resetted" then
			player.leaderstats.Stage.Value = 1
			player.TeleportedStage.Value = 1
			wait(0.1)
			teleport()
		end
	end)

	local Players = game:GetService("Players")

	Players.PlayerAdded:Connect(function(player)
		local tStage = Instance.new("StringValue")
		tStage.Name = "TeleportedStage"
		tStage.Parent = player
		wait(0.5)
		tStage.Value = player.leaderstats.Stage.Value
	end)

	local function onCharacterAdded(character)
		wait(0.1)
		print("CharacterAdded")
		local plr = Players:FindFirstChild(character.Name)
		local tar = game.Workspace.Stages:FindFirstChild(plr.TeleportedStage.Value)
		local tarp = tar.Position

		if tarp then
			wait(0.5)
			character:MoveTo(tarp)
		end
	end

	local function onPlayerAdded(player)
		player.CharacterAdded:Connect(onCharacterAdded)
	end
end
------
local function OnRespawn()
	local script1 = Instance.new("LocalScript", sp.StarterCharacterScripts)
	script1.Name = "OnRespawn"

	local rps = game:GetService("ReplicatedStorage")

	rps.ChangeStageByTechy:FireServer("respawned")
end

local MarketplaceService = game:GetService("MarketplaceService")
local productId = settings.skipStageProductID

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local players = game.Players:GetPlayers()
	local done = 0

	for i=1,#players do
		if players[i].userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == productId and done == 0 then
				done = 1
				players[i].leaderstats.Stage.Value = players[i].leaderstats.Stage.Value + 1
				players[i].TeleportedStage.Value = players[i].leaderstats.Stage.Value
				players[i].Character:MoveTo(game.Workspace.Stages:FindFirstChild(players[i].TeleportedStage.Value).Position)
				done = 0
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

if settings.skipStageProductID == 0 then
	game.StarterGui:FindFirstChild("StageTransfer").SkipStage:Destroy()
end
----
coroutine.wrap(SavingScript)()
coroutine.wrap(StageScript)()
coroutine.wrap(StageTransfer)()
coroutine.wrap(OnRespawn)() -- Error happends here

Remote events can only communicate between the client and server. If you want to communicate with another server script you would use a Bindable event. It is important to not though that if a bindable event is fired from the server only the server can receive it. Also, sorry if any of the remote event code is wrong, I haven’t used one in ages.

Remote events:

ServerScript:

RemoteEvent:FireClient(Player, OtherValuesHere)  --Send
RemoteEvent.OnServerEvent:Connect(function(Player, OtherValuesHere)  --Receive
   --Code here
end)

LocalScript

RemoteEvent:FIreServer(ValuesHere) --Send
RemoteEvent.OnClientEvent:Connect(function(ValuesHere)  --Receive
   --Code here
end)

Bindable Events

Server/Local Scripts

RemoteEvent:Fire(ValuesHere)  --Send
RemoteEvent.Event:Connect(function(ValuesHere)  --Receive
   --Code here
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.