What do you want to achieve? Making a game where there’s a color that is picked, you have to stand on the color on a board and if you dont you die. I want to make a gui that changes the badckgroundcolor3 to a BRICK COLOR out of a table and then convert that back to a brick color for my main script,
What is the issue I have NO idea how to do this…
What solutions have you tried so far? Everything
The Gui’s Script for changing its color (SO FAR)
local Box = script.Parent
local BrickColors = {"Really red","Deep orange","New Yeller","Dark blue","Hot pink","Reddish Brown","Lime green","Magenta"}
local ChosenColor = BrickColors[math.random(1, #BrickColors)]
Box.BackgroundColor3 =
The Main Part that currently only scripted to get a random brickcolor from a list and delete all parts that arent it, but Im trying to make instead of random, the Gui’s hue in brickcolor.
function findBricks(ColorParts)
local ChosenColor = BrickColors[math.random(1, #BrickColors)]
for k,v in pairs(ColorParts:GetDescendants()) do
if v:IsA("BasePart") and v.BrickColor ~= BrickColor.new(ChosenColor) then
v.Transparency = 1
v.CanCollide = false
print(ChosenColor)
end
end
end
“It doesn’t work” isn’t sufficient context. I’m not able to discern your exact problem besides what you’ve posted in the thread which alone isn’t much. I read through it and from what I saw it only looked like you were unsure of how to configure the BackgroundColor3 of a Gui element according to a BrickColor.
Additionally my reply mainly just points out that you can convert between BrickColor and Color3 but it’s not really a direct solution in itself. For that, I’ll need extra context behind what isn’t working exactly.
First thing is that you’re changing the StarterGui copy of the ColorDisplay Gui. The changes you’re applying would only be seen by newly spawning players (or if ResetOnSpawn is false, then new players joining your game). The server should not be managing any Guis for any reason because it has no concept of a user interface.
StarterGui’s only purpose is to replicate its contents to each player’s PlayerGui when they respawn sans ResetOnSpawn false Guis which only replicate once and don’t get cleaned when the character respawns. For this you need to have the server send clients the colour choice such as via RemoteEvent.
Next problem would exist whether or not you modify the StarterGui copy of your ColorDisplay Gui and it’s that you aren’t making a BrickColor object out of ChosenColor. Your random code selects a string from the table but does not construct a BrickColor out of the string. In that case, the BackgroundColor3 line would try to read the Color index in the string which is nil which in turn evaluates to “set the BackgroundColor3 of Box to nil” which would throw an error.
In short: you need to change how you’re getting the colour displayed on your Gui. The server should only be responsible for selecting the new colour and managing the game state based on the chosen colour but it should not be handling any visuals. The server needs to give that information to the client so that the client can set Guis and such accordingly.
I could break it down further if you want. Obviously cases will be different between experiences but in terms of your problem specifically and the post I made:
Never touch StarterGui with scripts. Look to LocalScripts and the LocalPlayer’s PlayerGui.
1.2. Things in StarterGui don’t show up to anyone.
Use a RemoteEvent. Make the server give players the colour string with FireAllClients.
Use a LocalScript to connect to the RemoteEvent and change ColorDisplay instead.
Make a BrickColor after you do the randomisation for ChosenColor.
I mean, yes. It’s not just that issue I’m addressing but once you fix that you’ll find that you’ll encounter a slew of other issues which is what my post is targeting; tackling all the issues at one go, not one at a time. Letting them not be addressed is another Scripting Support thread waiting to be created.
Here’s an example file I whipped up that’s putting my advice to practice to a degree, since I don’t currently have the time to create a near-similar repro to your current setup. The LocalScript handling the Gui’s colour is in StarterPlayerScripts and the server script handling sending the colour as well as picking a random one is in ServerScriptService.
place a model inside of workspace named ‘Touchpads’
place bricks inside of the model preferably next to eachother like tiles
place a script into serverscriptservice, name it whatever you want
paste this code into your script, this is just an example.
local bricks = workspace.Touchpads:GetChildren()
local colors = {"Really blue", "Really red", "Lime green", "Deep blue", "Institutional white"}
for i,v in pairs(bricks:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
if game.Players:GetPlayerFromCharacter(character) then
local player = game.Players:GetPlayerFromCharacter(character)
local playertouched = player:FindFirstChild("TouchedColor")
if playertouched then
playertouched.Value = v.BrickColor
end
end
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
local val = Instance.new("StringValue")
val.Parent = player
val.Name = "TouchedColor"
end)
while wait(1) do
local radcolor = colors[math.random(1,#colors)]
local radbrick = bricks:GetChildren()[math.random(1,#bricks:GetChildren())]
radbrick.Color = radcolor
for i,v in pairs(bricks:GetChildren()) do
if v ~= radbrick then
repeat wait()
v.BrickColor = BrickColor.Random()
until v.BrickColor ~= radcolor
end
end
wait(15)
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("TouchedColor") then
if v.TouchedColor.Value ~= radcolor then
if v.Character then
v.Character:BreakJoints()
end
end
end
end
end
Did you read my question? I already made the minigame script, I just need to make it so theres a gui that shows a color, and that color coresponds to the chosen color of the main script