Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Changing player appearance on Server Client?

Asked by 6 years ago

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)
0
You will need remote events, as the server cannot, and should not handle user input / GUI input. User#24403 69 — 6y

1 answer

Log in to vote
0
Answered by
Despayr 505 Moderation Voter
6 years ago
Edited 6 years ago

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)
Ad

Answer this question