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.
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)
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?
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.
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
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)