Character Selection button not working

  1. What do you want to achieve? Keep it simple and clear!

The system that I have already works, sort of. I wanted to make a character selection system where a player could click a button and they get to play the character - but only that player can use that character, and it shows who the character was taken by.

  1. What is the issue? Include screenshots / videos if possible!

This works, but only locally. Only one player can see this. All of the other players are unable to see that the character was taken - and they still can select it. This is annoying.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have looked for solutions on the developer hub, but can’t find anything. This is confusing, and I don’t know how to solve this.

The following is the code for the button:

SmartSelect.SelectButton.MouseButton1Click:Connect(function(LocalPlayer)
	if CanClick == true then
		CanClick = false
		
		local PlayerIcon = script.PlayerIcon:Clone()
		local TakenText = script.Taken:Clone()

		local BorderRadius = 3

		local NewSizeX = PlayerIcon.AbsoluteSize.X
		local NewSizeY = PlayerIcon.AbsoluteSize.Y
		local FrameSizeX = SmartSelect.Content.SmartIcon.AbsoluteSize.X
		local FrameSizeY = SmartSelect.Content.SmartIcon.AbsoluteSize.Y

		local RangeX = FrameSizeX - BorderRadius * 2 - NewSizeX
		local RangeY = FrameSizeY - BorderRadius * 2 - NewSizeY

		local PositionX = (math.random(RangeX) + BorderRadius + NewSizeX / 2) / FrameSizeX
		local PositionY = (math.random(RangeY) + BorderRadius + NewSizeY / 2) / FrameSizeY

		local UserID = Player.UserId
		local ThumbnailType = Enum.ThumbnailType.HeadShot
		local ThumbnailSize = Enum.ThumbnailSize.Size420x420
		local Content, IsReady = Players:GetUserThumbnailAsync(UserID, ThumbnailType, ThumbnailSize)

		PlayerIcon.Position = UDim2.new(PositionX, 0, PositionY, 0)	
		PlayerIcon.Parent = SmartSelect.Content.SmartIcon
		PlayerIcon.Image = Content

		TakenText.Parent = SmartSelect.Content.Information.RoleName
		TakenText.Text = "Taken by " ..Player.DisplayName

		Actors.Smart.Value = Player.Name
	else
		
	end
end)

Any help with this will be appreciated.

You’ll need a server script that listens for an event say “CharacterChoosen”. When the client picks a character the client script fires the CharacterChoosen event letting the server know what’s been choosen. The server then needs to send an event to each of clients informing them of what characters have been choosen. Once all clients are accounted for, start the game.

I don’t have a set of sample scripts on hand at the moment, maybe someone else has one they can share…

1 Like

yeah so basing off Lithdak’s answer this is the basic idea something i tried to whip up quickly give it a try

make two remote events under replicated storage i named them “takenCharacter” and “RemoteEvent”

--local script under button--

local RS = game:GetService("ReplicatedStorage")
local takenCharacter = RS:WaitForChild("takenCharacter")
local remote = RS:WaitForChild("RemoteEvent")
local characterName = "Yourcharacternamehere"
local canClick = true

script.Parent.MouseButton1Click:Connect(function()
	remote:FireServer(characterName) -- we gonna fire the character name to the server
end)

takenCharacter.OnClientEvent:Connect(function(character)
	if character == characterName then -- this is gonna check if we have to disable the button
		canClick = false
	end
end)

--server script under server script service--

local RS = game:GetService("ReplicatedStorage")
local remote = RS:WaitForChild("RemoteEvent")
local takenCharacter = RS:WaitForChild("takenCharacter")

remote.OnServerEvent:Connect(function(plr, character)
	takenCharacter:FireAllClients(character) -- this will fire to all clients
end)

ive never made something like this so sorry for any stupid mistakes i make

Doesn’t seem to work. I can’t seem to pinpoint what the problem is. I’ve put a bunch of prints, and still this is what happens:


Well what do the prints tell you? If it stops somewhere then that would tell us what works and what doesnt

I just tested this myself and it seems to work perfectly maybe share some of your code that you think is related

Since then I was able to get the prints working, now the only problem is that the “is taken” thing and the canclick doesn’t work and other players can still claim the character.

Remotes.TakenCharacter.OnClientEvent:Connect(function(Character)
	if Character == LunaticName then
		print("lunatic")
		local TakenText = script.Taken:Clone()
		TakenText.Parent = LunaticSelect.Content.Information.RoleName
		TakenText.Text = "Starring " ..Player.DisplayName
		
		CanClick = false
	elseif Character == SmartName then
		print("smart")
		local TakenText = script.Taken:Clone()
		TakenText.Parent = SmartSelect.Content.Information.RoleName
		TakenText.Text = "Starring " ..Player.DisplayName

		CanClick = false		
	elseif Character == DelusionalName then
		print("delusional")
		local TakenText = script.Taken:Clone()
		TakenText.Parent = LunaticSelect.Content.Information.RoleName
		TakenText.Text = "Starring " ..Player.DisplayName

		CanClick = false
	elseif Character == ParanoidName then
		print("paranoid")
		local TakenText = script.Taken:Clone()
		TakenText.Parent = LunaticSelect.Content.Information.RoleName
		TakenText.Text = "Starring " ..Player.DisplayName

		CanClick = false
	end
end)

Are you checking CanClick with an if statement? I dont believe you can simply do use an if statement to check if its set to false since if statements only run once.

and to clarify do these print? and does the text clone and such?

Assuming this is what you mean, I am checking the CanClick statement like this:

Button.MouseButton1Click:Connect(function()
    if CanClick == true then
       Canclick = false
    else

    end
end)

And yes, the prints do print

1 Like

do you have something to ensure that the button cannot be clicked again? If the prints do print and the texts does clone then the problem might be with how you handle CanClick.

I believe I do. For some reason it doesn’t apply to everyone, which has me really confused.

Honestly a simple fix would be to just set your image button visibility to false instead of using CanClick and maybe sub in a grayed out version of the image to show that its been taken

Still doesn’t show it to everyone, only the player that clicked it.

can you check that your are using FireAllClients and not FireClient?

Yes, I am using FireAllClients

this is really puzzling the event should not be received by only the player if it is being fired to all clients. Assuming that output and print analysis doesn’t print anything either this probably means that there is a condition only met by the player sending it and not everyone else? Can you send me your updated local and server script and I will try this out myself since I had gotten this work yesterday

I fixed it. I put the remote event in a PlayerAdded event, I didn’t realize this was the problem. Sorry for the frustration :sob:

no worries glad you fixed it
30char