-- LocalScript / StarterGui
local RS = game:GetService("ReplicatedStorage")
local colorEvent = RS:WaitForChild("Color")
local colorCode = {
["Red"] = Color3.new(255, 0, 0);
}
script.Parent.Red.MouseButton1Click:Connect(function()
colorEvent:FireServer(colorCode.Red)
print(colorCode.Red)
end)
-- Script / ServerScriptService
local RS = game:GetService("ReplicatedStorage")
local colorEvent = RS:WaitForChild("Color")
local part = RS:WaitForChild("PartTS"):FindFirstChild("NormalPart")
colorEvent.OnServerEvent:Connect(function(plr, colorCode)
print("Fired")
print(colorCode)
part.Color = Color3.new(colorCode)
print("Normal Part color Changed to",part.Color)
end)
-- Output
* 'print(colorCode.Red)': 255, 0, 0 <- Local Script
* 'print("Fired")': Fired <- Script
* 'print("colorCode)': 255, 0, 0 <- Script
* 'print("Normal Part color Changed to",part.Color)': 0, 0, 0 <- Here`s the problem
As I explained above, the problem is with the color, I don’t know why my NormalPart doesn’t change color, even though after detecting it from two sides LocalScript and Script, the color has the same code, but when I move it to NormalPart, the color becomes 0, 0 , 0 or black, maybe I’m using the FireServer function incorrectly. Please Help
I think the problem is because you’re using Color3.new instead of Color3.fromRGB, so try changing the first script to this:
-- LocalScript / StarterGui
local RS = game:GetService("ReplicatedStorage")
local colorEvent = RS:WaitForChild("Color")
local colorCode = {
["Red"] = Color3.fromRGB(255, 0, 0);
}
script.Parent.Red.MouseButton1Click:Connect(function()
colorEvent:FireServer(colorCode.Red)
print(colorCode.Red)
end)
Color3.new only accepts values between 1 and 0 (where 1 is equivalent to 255) while fromRGB accepts 0 to 255
Edit: You also need to change the server script like so:
-- Script / ServerScriptService
local RS = game:GetService("ReplicatedStorage")
local colorEvent = RS:WaitForChild("Color")
local part = RS:WaitForChild("PartTS"):FindFirstChild("NormalPart")
colorEvent.OnServerEvent:Connect(function(plr, colorCode)
print("Fired")
print(colorCode)
part.Color = colorCode
print("Normal Part color Changed to",part.Color)
end)
Really? never noticed that when passing a Color from client to server, it becomes a 1,1,1 on server side…
Well why dont you change the approach, and the color table should be on the server script, and the only thing that client send thru the remote is the name of the color?
local colorEvent = game:GetService"ReplicatedStorage".Color
local colorCode = {
Red = Color3.fromRGB(255, 0, 0)
}
script.Parent.Red.MouseButton1Click:Connect(function()
colorEvent:FireServer(colorCode.Red)
print(colorCode.Red)
end)
Server Script:
local replicatedStorage = game:GetService"ReplicatedStorage"
local colorCode = {
Red = Color3.fromRGB(255, 0, 0)
}
local part = replicatedStorage.PartTS.NormalPart
replicatedStorage.Color.OnServerEvent(function(_, color)
if typeof(color) == "string" then -- For security
if colorCode[color] then
print("Fired with color "..color)
part.Color = colorCode[color]
print("Normal part color changed to "..color)
else
warn(color.." is not found in server colorCode list")
end
end
end)