Script Fires Function When Player Joins

  1. I want to have this script not make the color change when you join

  2. I have a script that keeps firing when a person joins and I would like to have it so that it will only work if a player actually move the color picker

  3. I’ve tried making it a GetPropertyChanged and tried to make is so that if someone changes the colorDisplay it triggers a function and to not make it fire when a player just joins.

The script keeps updatingColor and I would like to have it so that it only works when a player actually moves the position of it. It keeps doing it when I join which messes up alot of my other code. Any guidance on what I did wrong would mean alot.

Code
local wheelPicker = colourWheel:WaitForChild("Picker")

local darknessPicker = script.Parent:WaitForChild("DarknessPicker")
local darknessSlider = darknessPicker:WaitForChild("Slider")

local colourDisplay = script.Parent:WaitForChild("DisplayName")


local Normal = script.Parent:WaitForChild("Normal")
local Bold = script.Parent:WaitForChild("Bold")
local SemiBold = script.Parent:WaitForChild("SemiBold")

local FontEvent = game.ReplicatedStorage.SetFont

local RemoteEventLocation = game.ReplicatedStorage.SetColour

local uis = game:GetService("UserInputService")


local buttonDown = false
local movingSlider = false

Normal.MouseButton1Click:Connect(function()

	local color = Enum.Font.Gotham
	script.Parent.DisplayName.Font = Enum.Font.Gotham
	FontEvent:FireServer(color)
end)

Bold.MouseButton1Click:Connect(function()

	local color = Enum.Font.GothamBold
	script.Parent.DisplayName.Font = Enum.Font.GothamBold
	FontEvent:FireServer(color)
end)

SemiBold.MouseButton1Click:Connect(function()

	local color = Enum.Font.GothamSemibold
	script.Parent.DisplayName.Font = Enum.Font.GothamSemibold
	FontEvent:FireServer(color)
end)

local Players = game:GetService("Players")

local player = Players.LocalPlayer


-- Fetch the thumbnail
wait(5)
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

-- Set the ImageLabel's content to the user thumbnail
local imageLabel = script.Parent.Thumbnail
imageLabel.Image = content


script.Parent.DisplayName.Text = game.Players.LocalPlayer.DisplayName
script.Parent.RankName.Text = game.Players.LocalPlayer.Name

local Player = game.Players.LocalPlayer -- assuming this is in a LocalScript
local groupId = 7354329

local PlayerRankInGroup = Player:GetRoleInGroup(groupId)
script.Parent.RankText.Text = PlayerRankInGroup


local function updateColour(centreOfWheel)


	local colourPickerCentre = Vector2.new(
		colourWheel.Picker.AbsolutePosition.X + (colourWheel.Picker.AbsoluteSize.X/2),
		colourWheel.Picker.AbsolutePosition.Y + (colourWheel.Picker.AbsoluteSize.Y/2)
	)
	local h = (math.pi - math.atan2(colourPickerCentre.Y - centreOfWheel.Y, colourPickerCentre.X - centreOfWheel.X)) / (math.pi * 2)

	local s = (centreOfWheel - colourPickerCentre).Magnitude / (colourWheel.AbsoluteSize.X/2)

	local v = math.abs((darknessSlider.AbsolutePosition.Y - darknessPicker.AbsolutePosition.Y) / darknessPicker.AbsoluteSize.Y - 1)


	local hsv = Color3.fromHSV(math.clamp(h, 0, 1), math.clamp(s, 0, 1), math.clamp(v, 0, 1))

	colourDisplay.TextColor3 = hsv
	darknessPicker.UIGradient.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, hsv), 
		ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
	}
end


colourWheel.MouseButton1Down:Connect(function()
	buttonDown = true
end)

darknessPicker.MouseButton1Down:Connect(function()
	movingSlider = true
end)


uis.InputEnded:Connect(function(input)

	if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end

	buttonDown = false
	movingSlider = false
end)


uis.InputChanged:Connect(function(input)

	if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end


	local mousePos = uis:GetMouseLocation() - Vector2.new(0, game:GetService("GuiService"):GetGuiInset().Y)

	local centreOfWheel = Vector2.new(colourWheel.AbsolutePosition.X + (colourWheel.AbsoluteSize.X/2), colourWheel.AbsolutePosition.Y + (colourWheel.AbsoluteSize.Y/2))

	local distanceFromWheel = (mousePos - centreOfWheel).Magnitude


	if distanceFromWheel <= colourWheel.AbsoluteSize.X/2 and buttonDown then

		wheelPicker.Position = UDim2.new(0, mousePos.X - colourWheel.AbsolutePosition.X, 0, mousePos.Y - colourWheel.AbsolutePosition.Y)


	elseif movingSlider then

		darknessSlider.Position = UDim2.new(darknessSlider.Position.X.Scale, 0, 0, 
			math.clamp(
				mousePos.Y - darknessPicker.AbsolutePosition.Y, 
				0, 
				darknessPicker.AbsoluteSize.Y)
		)	
	end
	local hi = colourDisplay.TextColor3
	RemoteEventLocation:FireServer(hi)
	updateColour(centreOfWheel)
end)
1 Like

What color? Can you give some screenshots to show what you’re talking about?

Sure thing! Sorry if I was unclear but every time I join into the game it changes a BillboardGui.Textlabel’s TextColor3. I’m a bit confused as to what I’m doing wrong and why this script is making this happen. It should only work when the colourWheel.Picker’s position changes

So reading the script, it looks like you want to have a color wheel players can use to change their name color. Is this color wheel visible at all times?

The updateColour function is the one which changes the name’s text color. The InputChanged event’s function on line 113 is supposed to call this function when the mouse moves. Try joining the game and not moving your mouse at all. As soon as you move your mouse, it should immediately change to white.

The reason for this is that you are not specifying that the mouse movement actually occurred inside of the color wheel. After ensuring the input was a mouse movement on line 115, you don’t have any checks that would otherwise prevent updateColour from being called. Perhaps move the call from line 141 (always called when moving the mouse) to line 128 (only called when distanceFromWheel <= colourWheel.AbsoluteSize.X/2 is true, which is functionally similar to a collision check).

I am not sure what the purpose of moving the wheel picker on line 127 is, or really what a wheel picker even is. Providing a .rbxl file would give us more information to help you.

1 Like

I’ve gone ahead and tested the game, you are correct. If I keep my mouse still it does not fire.
This color picker is from a youtube tutorial which is why I’m having trouble finding the problem. The script I have requires a lot of different things so It wouldn’t work if I just provided it.

Tutorial:

Model From The Tutorial (Model Goes In Starter Gui)
https://www.roblox.com/library/6023759238/Colour-Wheel

Maybe try adding a wait(3) at the beginning of the script?

I’ve tried that and then it automatically makes the nametag white after the wait.

At the end of your piece of code, it activates the remote event and updateColour function without ever checking if the mouse button is down or moving the slider. I don’t know if this is the problem or not though.

A YouTube tutorial script … I see, I have to admit I didn’t know these existed outside series dedicated to teaching scripting. If you don’t want to change the structure of the script, you should just add a stipulation somewhere in the InputChanged function that makes it so that it only tries changing colors when the menu is open. Something like if menu.Visible == false then return end right before or right after the MouseMovement check.

It isn’t the problem. I added stipulation and that seemed to fix the problem. Thank you anyways!

That seemed to work, I appreciate the help!