Instances, Numbers, and Strings converted (Some to nil)

Hello! I’m making a gun and I’m making something like a UI that shows how much damage it took. Someone told me to use remote events so I also have to move the data through the arguments. When the arguments are received, though, in the server script, they are all mysteriously converted (Numbers to nil, instances to strings, etc.).
Local script inside gun tool:

local billboard = Instance.new("BillboardGui")
billboard.Parent = game.ServerStorage
local label = Instance.new("TextLabel")
label.Parent = billboard
label.BackgroundTransparency = 1
label.Font = Enum.Font.Oswald
label.TextColor3 = Color3.fromRGB(255, 0, 0)
label.TextSize = 50
label.Visible = true
label.TextStrokeTransparency = 0
local bullets = 5
local reload = false
local config = script.Parent.Configuration
script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if bullets > 1 then
			if reload == false then
				local part = mouse.Target
				local hum = part.Parent:FindFirstChild("Humanoid")
				if hum then
					if part.Name == "Head" then
						hum.Health -= config.Headshot.Value
						game.ReplicatedStorage.GunGUI:FireServer(game.ServerStorage:FindFirstChild("BillboardGui"), game.ServerStorage.BillboardGui:FindFirstChild("TextLabel"), true, 1, 25)
						print("HEADSHOT")
						bullets -= 1
					end
				end	
			end
--Rest of the script

(The rest of the code is reloading)
Server script in server script service:

game.ReplicatedStorage.GunGUI.OnServerEvent:Connect(function(billboard, label, alwaysontop, zindex, text)
	local list = {billboard, label, alwaysontop, zindex, text}
	for i = 1, #list do
		print(typeof(list[i]))
	end
	print(typeof(label))
	billboard.AlwaysOnTop = alwaysontop
	label.ZIndex = zindex
	label.Text = text
end)

(The typeof was when I was looking at what happened to the code so don’t mind if some parts of the code that should be there (GUI parent) aren’t there)
I’d appreciate it if you’d help me. Thanks. :grinning_face_with_smiling_eyes:

Common mistake, Roblox provides an additional player parameter so it should be

Connect(function(player, billboard

The order matters a lot as it specifies which variable is which for the function.

2 Likes

I just did that, but it still counts the billboard as the player even though in the local script I put local player and in the server script I added DONTMINDTHIS (because I don’t even need the player)

Remotes do not need to be fired with the player. The player who fired the remote is implicitly passed as an argument to remotes, removing the need to do so from the developer. You only need to add a parameter for the player on the server’s end, you do not need to match it with an argument from the client. See RemoteEvent for documentation and examples.

Based on typeof (I only used it on every value except for the player) I got the billboard still an instance, the label and alwaysontop nil, zindex a boolean, and text a number (which is what I wanted).

Btw you cannot access server storage from the client as it’s well server storage.

A container whose contents are only accessible on the server. Objects descending from ServerStorage will not replicate to the client and will not be accessible from LocalScripts

.

As a result it will be nil or error.

1 Like

I removed all references to the server from the local script and just parented the billboard to workspace/server storage in the script. The problem is billboard is still nil.

Third issue I believe is that you are creating the gui from the client. Sever and client instances do not replicate, use a shared gui created by the server instead.

I suggest studying the client server model further.

And print/type checking on both sides client and server

1 Like

Thanks for the help! I’ll study this client server model more to prevent any more errors :slight_smile: