Making a Decal change ServerSided with GUI?

hello! I Want to make it so that when a player presses a GUI button, it changes the mouth decal

The problem here is that its Client sided, and I want it to be server side so everyone can see the change.

unfortunately I’ve searched the forums and a multitude of videos and I have found no solution thus far, And help would be very very much appreciated!
another thing to note is that I am using a custom model.

here is the script i am currently using for the decal change, it is a local script in starterGUI

local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
	character = player.Character
until character
local hum = character:WaitForChild("Humanoid")

script.Parent.MouseButton1Click:connect(function()
	character.Mouth.Decal.Texture = "http://www.roblox.com/asset/?id=14080059972" 
end)
2 Likes

Youll have to use a “Remote event” for this. Remote events are used to communicate between the client/server. If you want a more in detph guide id recommend reading through this: RemoteEvent | Documentation - Roblox Creator Hub


For your use case youll have to insrt a remote event into “ReplicatedStorage” and have the server listen to it whenever a client fires it.

Heres a quick example i wrote for you:

Server:

local Remote = game.ReplicatedStorage.RemoteEvent

-- This function will be fired once the remote has been triggered.

-- First argument is always the player who fired the remote.
local function MyEvent(Player, Value)
	print(Value)
end



Remote.OnServerEvent:Connect(MyEvent) 

Client:

local Remote = game.ReplicatedStorage.RemoteEvent


local Plr = game.Players.LocalPlayer

local Btn = Plr.PlayerGui.ScreenGui.Button


Btn.MouseButton1Click:Connect(function()
	Remote:FireServer("Hello from client :D")  
end)

Also just a small tip: Dont use “connect” thats deprecated. Use “Connect” instead.

1 Like

Alright, so I went ahead and tried this, it didn’t work. its possible its something I did wrong.

there Wasn’t an Error in the output.
By the way I’m assuming I put the Server script in the ServerScriptService?

if you need any specifics just ask!

Would you mind if i took a look at it to see whats wrong?

1 Like

take a look at what exactly? if you do not mind my asking

1 Like

Client + server code. Specifically the parts where youre:

  • Firing the remote on the client.

  • Listening to the remote on the server.

1 Like

probably should have mentioned this earlier- but I am still pretty new to scripting

I mostly just copied the example script you had gave me

local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
	character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
playing = false
local Remote = game.ReplicatedStorage.RemoteEvent

local Btn = player.PlayerGui["Emotes and more"]["Faces scrolling"].Eyes.Eyeoballs["Eyes9-17"]


Btn.MouseButton1Click:Connect(function()
	if playing == false then
		emote:Play()
		playing = true
		character.Visor.Decal.Texture = "http://www.roblox.com/asset/?id=14217848374"
elseif playing == true then
	emote:Stop()
	playing = false
	character.Visor.Decal.Texture = "http://www.roblox.com/asset/?id=00000000000"
end
end)
local Remote = game.ReplicatedStorage.RemoteEvent

-- This function will fired once the remote has been triggered by a client.
local function MyEvent(Player, Value)
	print(Value)
end



Remote.OnServerEvent:Connect(MyEvent)

I know I probably had to change something on the server one but- I was unsure what exactly I had to change (please bare with me-)

1 Like

No worries :grin: everybody starts somewhere

I modified your code by a tiny bit:

Client:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
local playing = false
local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local Gui = player.PlayerGui:WaitForChild("Emotes and more")
local Faces = Gui:WaitForChild("Faces and scrolling")
local Btn = Faces:WaitForChild("Eyes"):WaitForChild("Eyeoballs"):WaitForChild("Eyes9-17")

Btn.MouseButton1Click:Connect(function()
	if playing == false then
		emote:Play()
		playing = true
		Remote:FireServer("http://www.roblox.com/asset/?id=14217848374")
	elseif playing == true then
		emote:Stop()
		playing = false
		Remote:FireServer("http://www.roblox.com/asset/?id=00000000000")
	end
end)

Server(Place inside ServerScriptService)

local Remote = game.ReplicatedStorage.RemoteEvent

-- This function will fired once the remote has been triggered by a client.
local function MyEvent(Player, Texture: string)
	local Visor = Player.Character.Visor

	Visor.Decal.Texture = Texture
end



Remote.OnServerEvent:Connect(MyEvent)
2 Likes

It worked! thank you so much your a life saver!!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.