LocalScript in to ServerSide

Wait… it’s still not working. When I put in the username of a player other than myself, it does nothing. :frowning:

Alright, thank you! (30 ch.rss)

I think it has to be related to something in the code that checks the player, could you send me your RemoteEvent code and perhaps an example of what’s going on

Sure!

ServerScript:

local Event = game.ReplicatedStorage:WaitForChild("HostRole")

Event.OnServerEvent:Connect(function(plr, text)
	local Characters = string.lower(text)
	
	for i, player in pairs(game.Players:GetPlayers()) do
		local PlrName = string.lower(plr.Name)

		if string.sub(PlrName,1,#Characters) == Characters then
			plr.Character.Rank.Frame.TextLabel.Text = "Host"
			plr.Team = game.Teams.Host
		end
	end
end)

LocalScript:

local TextEvent = game.ReplicatedStorage:WaitForChild("HostRole")
local RankButton = script.Parent

RankButton.Activated:Connect(function()
    TextEvent:FireServer(script.Parent.Parent.Parent.UsernameBox.TextBox.Text)
end)

Issue:

https://drive.google.com/file/d/12xGju-OU9gGJPvsh4QUaa3QvZ62Yu-fD/view

I see the issue! You’re using the plr parameter of the RemoteEvent that is given automatically, it returns the player who activated the event, you’re checking it with that and not the other players, that’s why it only works for you! This code

local PlrName = string.lower(plr.Name)

if string.sub(PlrName,1,#Characters) == Characters then
	plr.Character.Rank.Frame.TextLabel.Text = "Host"
	plr.Team = game.Teams.Host
end

Change every plr to player

local PlrName = string.lower(player.Name)

if string.sub(PlrName,1,#Characters) == Characters then
	player.Character.Rank.Frame.TextLabel.Text = "Host"
	player.Team = game.Teams.Host
end
1 Like

This fixed it, thank you so much! EDIT: I QUOTED THE WRONG THING, SORRY.

1 Like

This fixed it, thank you so much!

1 Like

I’m glad it helped you out! And haha, it’s fine, you can edit your quote to feature the correct code! If you have anymore issues don’t be afraid to make another post!

1 Like

Ahhh, one more thing. What script would I insert to make an image of the players’ head who was assigned the role show on the GUI for all players? :heart:

I believe something like this would work

local Event = game.ReplicatedStorage:WaitForChild("HostRole")

local thumbsize = Enum.ThumbnailSize.Size100x100 --The size for the image
local thumbtype = Enum.ThumbnailType.HeadShot --The type of image you want

Event.OnServerEvent:Connect(function(plr, text)
	local players = game.Players:GetPlayers()
	local Characters = string.lower(text)
	
	for i, player in pairs(players) do
		local PlrName = string.lower(player.Name)

		if string.sub(PlrName,1,#Characters) == Characters then
			player.Character.Rank.Frame.TextLabel.Text = "Host"
			player.Team = game.Teams.Host
			local img, ready = game.Players:GetUserThumbnailAsync(player.UserId,thumbtype,thumbsize) --Create Image
			for _,plrs in pairs(players) do --Loop through players again to set the image
				plrs.PlayerGui.(proceed with location of image label).Image = img
			end
			break --Stop the first loop since we found our player
		end
	end
end)

In the condition after finding the player, it’ll get their thumbnail, loop through the players again and set a specific image label to their thumbnail and break the first loop since a player was found and we don’t want it continue with the other players. Probably not the most optimal, but it should work

Edit: I"m not sure if it’ll work after respawn, if it doesn’t, add

game.StarterGui.(location of image label).Image = img 

before the

for _,plrs in pairs(players) do --Loop through players again to set the image
	plrs.PlayerGui.(proceed with location of image label).Image = img
end

loop so it sets it there as well when they respawn

1 Like

You’re not meant to send the Player. The Remote already does it.

Thank you, I’ll give this a go.

@EmbatTheHybrid ?? (30 ch.rsss)

I think he’s referring to something else as you’re not sending the player with the event

1 Like

This worked. Seriously, thank you so much. The fact that you’re doing this all out of kindness stuns me.

1 Like

I’m glad that it worked! And of course I would spend my time to try and help the best taht I can, it’s the reason why this category even exists, to help people like you with problems you don’t know how to fix! If you have anymore issues don’t be afraid to make another post, and who knows, maybe I’ll be the one that to also help you with that one too!

1 Like

:grinning_face_with_smiling_eyes:

I also am wondering how to make it auto-fill the rest of the players’ username in the TextBox as it’s PlaceHolderText once the first few letters of it is typed, would you know how to do this?

Do you mean when you write the first few letters of a player’s name, as soon as you stop focusing on the Textbox, aka, clicking off it for example, it autofills it with the player it found?

1 Like

Hm, I’m hoping it does it while the player is typing in the username.

So like, when you type a letter, it will autofill it with that it thinks you wanted to write, and if it wasn’t that, you can just easily continue to get the player

Like example, you want to get the player “Embat”

“E” - “Ebamc”
“Em” - “Emah”
“Emb” - “Embat”

Basically, you press a key, it autofills it for you, if it wasn’t that, you can easily continue on typing letters til lyou get the right player?

1 Like