Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing player appearance on Server Client?

I'm having trouble understanding how exactly could I make changes to a player and have other players around see those changes. How would I go about dealing with this problem?

Here's an example on a local script

local button = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character

button.MouseButton1Click:Connect(function()
	for i, v in pairs(char:GetChildren()) do
		if v:IsA('MeshPart') or v:IsA('Part') then
			v.BrickColor = BrickColor.new(math.random(), math.random(), math.random())
		end
	end
end)

1 comment

0

You will need remote events, as the server cannot, and should not handle user input / GUI input.

1 answer

✓ Accepted answer

You will need a remote event to be fired to achieve this.

Put this code into the local script

localscript

local button = script.Parent
local Players = game:GetService("Players") --Use :GetService as the script could break if an exploiter changes the name of "Players". This prevents that.
local player = Players.LocalPlayer
local Character = player.Character
local Storage = game:GetService("ReplicatedStorage")

local event = Storage:FindFirstChild("RemoteEvent") -- This will fire the serverscript.

button.MouseButton1Click:Connect(function()
	event:FireServer()
end)

Add a serverscript into the serverscriptservice and write this code

serverscript

--put this script inside of serverscriptservice
local Storage = game:GetService("ReplicatedStorage")

Storage:FindFirstChild("RemoteEvent").OnServerEvent:Connect(function(Player)

	local Character = Player.Character

	for i, v in pairs(Character:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("Part") then
			v.BrickColor = BrickColor.new(math.random(), math.random(), math.random())
			end
end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.