Remote Event Not Firing Properly

I am trying to make a script that changes the color of the player’s name, but the arguments are not firing properly

Local Script:

local c = script.Parent:GetChildren()
local ChangeColor = game.ReplicatedStorage.ChangeNameColor

for i = 1, #c do
	if c[i]:IsA("TextButton") then
		c[i].MouseButton1Click:Connect(function(Plr)
			local Color = c[i].BackgroundColor3
			local h, s, v = Color:ToHSV()
			ChangeColor:FireServer(Plr, h, s, v)
			print(h, s, v)
		end)
	end
end

Server Script:

local remoteEvent = game.ReplicatedStorage.ChangeNameColor

remoteEvent.OnServerEvent:Connect(function(Plr, h, s, v)
	local char = Plr.Character or Plr.CharacterAdded:Wait()
	local nameGui = char.Head:FindFirstChild("NameGui")
	local nameLabel = nameGui:FindFirstChild("NameLabel")
	print(h, s, v)
	nameLabel.TextColor3 = Color3.fromHSV(h, s, v)
end)

Here’s what is in the output:
I don’t know why it is printing nil.
image

1 Like

[spoiler] this belongs in Help and Feedback > Scripting Support [/spoiler]

image

When you fire a remote event your player object is automatically passed as the first argument so you passing Plr yourself is redundant.

These are the arguments that will be passed

Player, Player, h, s, v

because Player is already automatically passed as the first argument.

You should be doing this instead

ChangeColor:FireServer(h, s, v)
1 Like

How would I get the player’s character if I do not fire the Player? Also I am new to the DevForum so I don’t know how to put it in scripting support.

Because the player object is already automatically passed as the first argument. Let me give an example:

-- local script
RemoteEvent:FireServer("Hi")
-- server
RemoteEvent.OnServerEvent:Connect(function(Player, Message)
    print(Player, Message) -- ScriptingSausage, "Hi"
end)

The player is automatically the first argument and the other arguments you gave are shoved after it.


When I tried it, it wasn’t working.

Local Script:

local c = script.Parent:GetChildren()
local ChangeColor = game.ReplicatedStorage.ChangeNameColor

for i = 1, #c do
	if c[i]:IsA("TextButton") then
		c[i].MouseButton1Click:Connect(function()
			local Color = c[i].BackgroundColor3
			local h, s, v = Color:ToHSV()
			ChangeColor:FireServer(h, s, v)
			print(h, s, v)
		end)
	end
end

Server Script:

local remoteEvent = game.ReplicatedStorage.ChangeNameColor

remoteEvent.OnServerEvent:Connect(function(h, s, v)
	local char = Player.Character or Player.CharacterAdded:Wait()
	local nameGui = char.Head:FindFirstChild("NameGui")
	local nameLabel = nameGui:FindFirstChild("NameLabel")
	print(h, s, v)
	nameLabel.TextColor3 = Color3.fromHSV(h, s, v)
end)

This is what it says in the output:
image

this should work

	local char = Plr.Character or Plr.CharacterAdded:Wait()

try doing print(Plr:GetFullName() to make sure it is the player

This was my first post so it didn’t let me change the category.

should be:

remoteEvent.OnServerEvent:Connect(function(Player, h, s, v)
1 Like
remoteEvent.OnServerEvent:Connect(function(h, s, v)
	local char = Player.Character or Player.CharacterAdded:Wait()

Player isnt a thing I think you removed Plr

These are the arguments that will be passed: Player, Player, h, s, v

@ScriptingSausage are you sure it wouldnt be Player, h, s, v? I dont think there is any reason there would be two, have you tried testing these exact arguments to confirm this?

It still says this:
image

yes, because Plr and Player arent defined at all

I was doing what ScriptingSausage suggested:

See my reply Remote Event Not Firing Properly - #9 by Vulkarin. ScriptingSausage was trying to explain to you that RemoteEvent:OnServerEvent() has a default first parameter of the player object who fired the event.

That means that way back in your original post code, you can just change:

to

ChangeColor:FireServer(h, s, v)

because the player object is always the first argument sent to the event by default.

Yeah I know but doesnt he need the player argument, he needs the HSV for the color not the SV for color and the H for the player

I honestly have no idea what you are trying to say. His parameters will then be: (Plr, h, s, v) with ‘Plr’ serving as the player object, not h.

local c = script.Parent:GetChildren()
local ChangeColor = game.ReplicatedStorage.ChangeNameColor

for i = 1, #c do
	if c[i]:IsA("TextButton") then
		c[i].MouseButton1Click:Connect(function(Plr)
			local Color = c[i].BackgroundColor3
			local h, s, v = Color:ToHSV()
			ChangeColor:FireServer(h, s, v)
			print(h, s, v)
		end)
	end
end

Do this and keep your original server script

Thats what im saying he needs to get the character, thats why he is using player

Yes? What are you implying needs to change…?

Was just saying that I dont think removing the player argument will solve the problem

Here is a very basic code for sending over the player and 3 values on a remote event.

local script

local event = game.ReplicatedStorage.Event
local h, s, v
event:FireServer(h, s, v)

server script

local event = game.ReplicatedStorage.Event
Event.OnServerEvent:Connect(function(Player, h, s, v)
    --Get player character with Player.Character. Use H S V as normal variables
    print(Player, h, s, v)
end)

Hope this helps!

1 Like