I’ve been working on this goofy game, and I wanted to make some type of character customization.
The customization I added so far was being able to change the material of your player but when I tried to test the script it just changes all players material instead of the the main one who wants their material changed.
Button Script
local Player = game.Players.LocalPlayer
local PlrGui = Player.PlayerGui
local MaterialManager = PlrGui:WaitForChild("MaterialManager")
local VPMBody = MaterialManager.ViewportFrame.WorldModel.ViewportModel:WaitForChild("BODY")
local MatChangedRemote = game.ReplicatedStorage:WaitForChild("MaterialChanged")
script.Parent.MouseButton1Click:Connect(function()
VPMBody.Material = Enum.Material.Neon
MatChangedRemote:FireServer("Neon")
end)
Script that changes the player material
local MatChangedRemote = game.ReplicatedStorage:WaitForChild("MaterialChanged")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
MatChangedRemote.OnServerEvent:Connect(function(plr, state)
if state == "Neon" then
local Body = character:WaitForChild("BODY")
Body.Material = Enum.Material.Neon
end
end)
end)
end)
You should only define the OnServerEvent thing once, and use the plr variable to access the player’s character.
So the server script should be:
local MatChangedRemote = game.ReplicatedStorage:WaitForChild("MaterialChanged")
local Players = game:GetService("Players")
MatChangedRemote.OnServerEvent:Connect(function(plr, state)
if state == "Neon" then
local Body = plr.Character:WaitForChild("BODY")
Body.Material = Enum.Material.Neon
end
end)
Note that if the player dies, it won’t reupdate their character. If that is a requirement, let me know.
Simplest way would probably be using a dictionary, something like this:
local MatChangedRemote = game.ReplicatedStorage:WaitForChild("MaterialChanged")
local Players = game:GetService("Players")
local Mapping = {}
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if Mapping[plr] then
plr.Character:WaitForChild("BODY").Material = Mapping[plr]
end
end)
end)
MatChangedRemote.OnServerEvent:Connect(function(plr, state)
if state == "Neon" then
local Body = plr.Character:WaitForChild("BODY")
Body.Material = Enum.Material.Neon
Mapping[plr] = Enum.Material.Neon
end
end)