Remote event not working?

When you click a button it fires a remote event and adds whatever skin colour you have selected in the colour picker gui

The issue is there’s 0 errors however it isn’t working. IT WORKS if i put it in a local script,but when i add a event so everyone can the skin tone it doesn’t work.

local rs = game.ReplicatedStorage
local event = rs.RemoteEvents.SkinTones
function OnClick()
	local function playerg(character)
		for _, player in pairs (game:GetService("Players"):GetPlayers()) do
			if player.Character == character then
				return player
			end
local Skins = player.Parent:FindFirstChild("BodyColors")
if (Skins == true) then return end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	skin.Parent = player.Character
	skin.HeadColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.LeftArmColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.RightArmColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.TorsoColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.RightLegColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.LeftLegColor = BrickColor.new(color.Preview.BackgroundColor3)
		end
	end
end

event.OnServerEvent:Connect(OnClick)

ABOVE is the script after it’s been fired

local rs = game.ReplicatedStorage.RemoteEvents
local event = rs.SkinTones

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer()
end)

Above is the button being clicked.

image

image

What is the playerg function for? The first argument passed to a OnServerEvent is the player who called it, plus where is it called in the script and where is player defined? Maybe instead of using a function to get the player do something like this:

function OnClick(player)
local Skins = player.Parent:FindFirstChild("BodyColors")
  if (Skins == true) then return end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	skin.Parent = player.Character
	skin.HeadColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.LeftArmColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.RightArmColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.TorsoColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.RightLegColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.LeftLegColor = BrickColor.new(color.Preview.BackgroundColor3)
end 
1 Like

So will it get the player already? So the playerg function is pointless.

Yeah, the first argument of a function fired by a remote event represents the player who fired it. (At least on the server)

1 Like

Okay, thanks. I over complicated it lmao

I think I see your problem here, you shouldn’t be able to access the playergui object (besides it being there) though the server, you’ll have to use a fire client event in the server script for it to work.

1 Like

Thanks everyone for helping it’s kind

1 Like

Yea, it’s going white and not colouring in and it’s not giving an error?

What’s going white the character or the screen?

The stage and skin colours that i am trying to colour in is going white instead of colouring in, the colour gui is all linked and works fine with everything else

https://gyazo.com/7b8d970a3f24705ad52864a58c50ad70

local IsOn = false
local stage = game.StarterGui.StageChanger.Colors.Page.Frame.Color.Preview
local rs = game.ReplicatedStorage
local event = rs.RemoteEvents.SkinTones


function OnClick(player)
local Skins = player.Parent:FindFirstChild("BodyColors")
  if (Skins == true) then return end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	skin.Parent = player.Character
	skin.HeadColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.LeftArmColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.RightArmColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.TorsoColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.RightLegColor = BrickColor.new(color.Preview.BackgroundColor3)
	skin.LeftLegColor = BrickColor.new(color.Preview.BackgroundColor3)
end 




event.OnServerEvent:Connect(OnClick)

Try using Color3.fromRGB instead of BrickColor.new because quoted from the wiki Color3.fromRGB

Constructs the closest BrickColor that can be matched to the specified RGB components.:

local Color =  color.Preview.BackgroundColor3 
local R,G,B = Color.R, Color.G, Color.B
skin.HeadColor =  Color3.fromRGB(R,G,B)

Does it still go white if you go to entirely black? I haven’t gotten BrickColor from BackgroundColor3 so it could be a fromRGB() thing.

It worked when it was in a local script and they were changing colours, but i’ll try change it

Brickcolor expected, Got Color3

local IsOn = false
local stage = game.StarterGui.StageChanger.Colors.Page.Frame.Color.Preview
local rs = game.ReplicatedStorage
local event = rs.RemoteEvents.SkinTones


function OnClick(player)
local Skins = player.Parent:FindFirstChild("BodyColors")

  if (Skins == true) then return end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	local Color =  color.Preview.BackgroundColor3 
	local R,G,B = Color.R, Color.G, Color.B
	skin.HeadColor =  Color3.fromRGB(R,G,B)
	skin.Parent = player.Character
	skin.HeadColor = Color3.fromRGB(R,G,B)
	skin.LeftArmColor = Color3.fromRGB(R,G,B)
	skin.RightArmColor = Color3.fromRGB(R,G,B)
	skin.TorsoColor = Color3.fromRGB(R,G,B)
	skin.RightLegColor = Color3.fromRGB(R,G,B)
	skin.LeftLegColor = Color3.fromRGB(R,G,B)
end 




event.OnServerEvent:Connect(OnClick)
1 Like

Made a mistake i think it’s actually supposed to be Color.new instead, Oh and make sure that you are changing the color property not the brickcolor otherwise you’ll get that error you got:

function OnClick(player)
local Skins = player.Parent:FindFirstChild("BodyColors")

  if (Skins == true) then return end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	local Color =  color.Preview.BackgroundColor3 
	local R,G,B = Color.R, Color.G, Color.B
	skin.HeadColor =  Color3.new(R,G,B)
	skin.Parent = player.Character
	skin.HeadColor = Color3.new(R,G,B)
	skin.LeftArmColor = Color3.new(R,G,B)
	skin.RightArmColor = Color3.new(R,G,B)
	skin.TorsoColor = Color3.new(R,G,B)
	skin.RightLegColor = Color3.new(R,G,B)
	skin.LeftLegColor = Color3.new(R,G,B)
end

It said brickcolor expected got color3, so i did

function OnClick(player)
local Skins = player.Parent:FindFirstChild("BodyColors")

  if (Skins == true) then return end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	local Color =  color.Preview.BackgroundColor3 
	local R,G,B = Color.R, Color.G, Color.B
	skin.HeadColor3 =  Color3.new(R,G,B)
	skin.Parent = player.Character
	skin.LeftArmColor3 = Color3.new(R,G,B)
	skin.RightArmColor3 = Color3.new(R,G,B)
	skin.TorsoColor3 = Color3.new(R,G,B)
	skin.RightLegColor3 = Color3.new(R,G,B)
	skin.LeftLegColor3 = Color3.new(R,G,B)
end



event.OnServerEvent:Connect(OnClick)

And it coloured it however it was white?

Yeah i meant to put the 3 after the properties, but i am confused as to why it’s not working, i tried this and it seemed to work for me. Are you sure, you are using the right Gui?

Yea… Strange idk why it’s not working. I’ll show you it all

local IsOn = false
local stage = game.StarterGui.StageChanger.Colors.Page.Frame.Color.Preview
local rs = game.ReplicatedStorage
local event = rs.RemoteEvents.SkinTones


function OnClick(player)
local Skins = player.Parent:FindFirstChild("BodyColors")

  if (Skins == true) then 
	return 
	end
	local skin = Instance.new("BodyColors")
	local color = player.PlayerGui["Skintone Changer"].Frame.Page.Frame.Color
	local Color =  color.Preview.BackgroundColor3 
	local R,G,B = Color.R, Color.G, Color.B
	skin.HeadColor3 =  Color3.new(R,G,B)
	skin.Parent = player.Character
	skin.LeftArmColor3 = Color3.new(R,G,B)
	skin.RightArmColor3 = Color3.new(R,G,B)
	skin.TorsoColor3 = Color3.new(R,G,B)
	skin.RightLegColor3 = Color3.new(R,G,B)
	skin.LeftLegColor3 = Color3.new(R,G,B)
end



event.OnServerEvent:Connect(OnClick)

Script that executes the colors ^^^

local rs = game.ReplicatedStorage.RemoteEvents
local event = rs.SkinTones

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer()
end)

If clicked activate event script ^^^^

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local TargetFrame = script.Parent:WaitForChild("Frame").Color

local rgb = TargetFrame:WaitForChild("RGB")
local value = TargetFrame:WaitForChild("Value")
local preview = TargetFrame:WaitForChild("Preview", 5)
local selectedColor = Color3.fromHSV(1, 1, 1)

local colorData = {
	1,
	1,
	1
}

local mouse1down = false

function setColor(hue, sat, val)
	colorData = {
		hue or colorData[1],
		sat or colorData[2],
		val or colorData[3]
	}
	selectedColor = Color3.fromHSV(colorData[1], colorData[2], colorData[3])
	preview.BackgroundColor3 = selectedColor
	value.ImageColor3 = Color3.fromHSV(colorData[1], colorData[2], 1)
end

function inBounds(frame)
	local x, y = Mouse.X - frame.AbsolutePosition.X, Mouse.Y - frame.AbsolutePosition.Y
	local maxX, maxY = frame.AbsoluteSize.X, frame.AbsoluteSize.Y
	if x >= 0 and y >= 0 and x <= maxX and y <= maxY then
		return x / maxX, y / maxY
	end
end

function updateRGB()
	if mouse1Down then
		local x, y = inBounds(rgb)
		if x and y then
			rgb:WaitForChild("Marker").Position = UDim2.new(x, 0, y, 0)
			setColor(1 - x, 1 - y)
		end
		local x, y = inBounds(value)
		if x and y then
			value:WaitForChild("Marker").Position = UDim2.new(0.5, 0, y, 0)
			setColor(nil, nil, 1 - y)
		end
	end
end

Mouse.Move:connect(updateRGB)

Mouse.Button1Down:connect(function()
	mouse1Down = true
end)

Mouse.Button1Up:connect(function()
	mouse1Down = false
end)

Colour Gui Script ^^^

image

image

image

All info is there :slight_smile: ALL help is apperciated

1 Like