FireServer not working correctly

So, this is the local script

local active = 1
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
	if game.Players.LocalPlayer:FindFirstChild("Functional").Crates.Value > 0 and active == 1 then
		active = 0 
		local a = require(player.PlayerGui.Modules.case):create()
		workspace.Openings.RemoteEvent:FireServer(a)
		wait(3)
		active = 1 
	end
end)

a when printed is a string
Server side


script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,a)
	print(a)
	if player:FindFirstChild("Functional").Crates.Value > 0 then
		player:FindFirstChild("Functional").Crates.Value = player:FindFirstChild("Functional").Crates.Value - 1
		if a == "1 Wins" then
			player:FindFirstChild("leaderstats").Wins.Value = player:FindFirstChild("leaderstats").Wins.Value + 1
		elseif a == "2 Wins" then
			player:FindFirstChild("leaderstats").Wins.Value = player:FindFirstChild("leaderstats").Wins.Value + 2
		elseif a == "3 Wins" then
			player:FindFirstChild("leaderstats").Wins.Value = player:FindFirstChild("leaderstats").Wins.Value + 3
		else
			if player.skins[a].Value == true then
				player:FindFirstChild("leaderstats").Wins.Value = player:FindFirstChild("leaderstats").Wins.Value + 1
			else
				player.skins[a].Value = true 
				print("Attempt")
			end
		end
	end
end)

when a is printed here for some reason it takes the string as a nil.

I’ll short some long part.

Client side

local active = true
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
	local crate = player:FindFirstChild("Functional").Crates.Value
	if crate > 0 and active then
		active = false 
		local a = require(player.PlayerGui.Modules.case):create()
		--Server can't access to PlayerScript. Same manner to PlayerGUI?
		workspace.Openings.RemoteEvent:FireServer(a,crate)
		wait(3)
		active = true
	end
end)

Server side

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,a,crate)
	local ls = player:FindFirstChild("leaderstats").Wins.Value
	print(a)
	if crate > 0 then
		player:FindFirstChild("Functional").Crates.Value = crate - 1
		if a == "1 Wins" then
			player:FindFirstChild("leaderstats").Wins.Value = ls + 1
		elseif a == "2 Wins" then
			player:FindFirstChild("leaderstats").Wins.Value = ls + 2
		elseif a == "3 Wins" then
			player:FindFirstChild("leaderstats").Wins.Value = ls + 3
		else
			if player.skins[a].Value == true then
				player:FindFirstChild("leaderstats").Wins.Value = ls + 1
			else
				player.skins[a].Value = true 
				print("Attempt")
			end
		end
	end
end)

“Same manner to PlayerGUI?” - Is that true, or are you asking a question?


Just Wondering.

What’s player.PlayerGui.Modules.case?

A case containing functions, it works without errors.

Try printing the string on the client side, see if it prints correctly

It does, A is printed as a string.

Well then.

local active = true
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
	local crate = player:FindFirstChild("Functional").Crates.Value
	if crate > 0 and active then
		active = false 
		local a = require(player.PlayerGui.Modules.case):create()
		workspace.Openings.RemoteEvent:FireServer(tostring(a),crate)
		wait(3)
		active = true
	end
end)

What’s in skins table that uses “a”, especially key side?

Hi @Memedealer2111 ,

You’re sending a Require (Functions) To The Server, This for some reason can not be made.
It is also correct because a function that is requested by the client must remain client and not server

Server can not execute a function that should be executed by the client.

This also applies to the Server - Client

Instead Save the Value that the function return in an External Variable (On Local script) and then send it

Also Make sure what “a” on client is

1 Like

A is just a string, from a selection of random strings. (This will always be a string). The string is sent to the server so we can use it there.

“a” is always a string, which is why I am confused.

Could you try to print this:

print(tostring(a)) ← On Client
Also Try this:

print(type(tostring(a)))

The type is appearing as an instance, but it has no properties.

Make module return string value.

1 Like

Then the create() method is returning an ‘Instance’ not a string value as you erroneously stated. Roblox objects instanced by the client do not replicate and thus from the server’s perspective, appear as ‘nil’.