Hello, I was wondering how to make it so the color of brick changes for only one person.
When somebody does a particular action I want the color of the brick to change for only them. How would I do that?
Hello, I was wondering how to make it so the color of brick changes for only one person.
When somebody does a particular action I want the color of the brick to change for only them. How would I do that?
Hello. You can try putting your code in a LocalScript
.
Do this in a local script, fire an event from the server to the client, you can use OnClientEvent
Wait, fire an Client Event to a LocalScript from a regular Script or the other way around?
Make a remote event, fire it from a server script by doing FireClient() then on the local script do OnClientEvent(), etc. You can fill in your parameters
Where would I put the LocalScript?
It completely depends upon your code.
Up to you, what do they do to activate the color change
The color would change if they owned a badge.
You can place it in starterplayerscripts if you want
That makes the color change for everybody.
I said LocalScript, meaning it’ll be replicated to the client only
(I swear if this needs to be placed in StarterPack again for the 500th time)
When I moved into a LocalScript, the Color doesn’t change.
Use my method not his, make a server script with badgeservice, if they own the badge fireclient() then in the local script do onclientevent and put the code
The Color doesn’t change. However, the rest of the script also doesn’t run so it may be a problem with Firing the Event. I’ll check the output.
My bad other way around, I’ll write the script for you soon as I’m home
If you want to make a color change for a specific player then you can use the FireClient()
function, this function allows you to transfer data on client from the server. So, for example, let’s say there is a button in a game and whoever clicked the button will have that button’s color change only for that player, here is the code.
Server
local Button = game.Workspace.Button
local RemoteEvent = game.ReplicatedStorage.ChangeColor -- create a remote event in ReplicatedStorage called "ChangeColor"
Button.ClickDetector.MouseClick:Connect(function(PlrWhoClicked) -- clicked is the player argument (btw)
RemoteEvent:FireClient(PlrWhoClicked, Button) -- the first argument is the player who you want to see the color block and the second argument is the button
end)
Client
local ChangeColor = game.ReplicatedStorage.ChangeColor -- retrieve the remote event from ReplicatedStorage
ChangeColor.OnClientEvent:Connect(function(Button)
Button.BrickColor = BrickColor.new("Really red") -- this will change the color of the button for the player who clicked the button only
end)
In your context, if you want to change a color of a part if someone has a badge then you need to use BadgeService and use the UserHasBadgeAsync()
to check whether the player has a badge, if they do then send a remote event. The UserHasBadgeAsync()
has 2 arguments, the userId of a player and the corresponding badgeID which you want to check if the player has, once you have done this, the function will return a boolean value determining whether or not the player has a badge.
I’ll give you this code and hopefully you will understand it in depth:
Server
local BadgeService = game:GetService("BadgeService")
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local BadgeID = -- your own badge ID which you can get from the website URL
local Button = game.Workspace.Button
game.Players.PlayerAdded:Connect(function(plr)
if BadgeService:UseHasBadgeAsync(plr.UserId, BadgeID) then
RemoteEvent:FireClient(plr, Button)
end
end)
Client
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent.OnClientEvent:Connect(function(Button)
Button.BrickColor = BrickColor.new("Really red")
end)
@gumixchan That is how you do it.
Would the part where you change the color be in a Server Script or a Local Script?
Local script because you want to change the color of the part for the client only.
Server → Script
Client → Localscript
I don’t think the RemoteEvent is firing correctly because the rest of the script where it fires doesn’t run.