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

Why are changes to the morph visible only to the client?

Asked by
snarns 25
7 years ago

My game relies heavily on character morphs. When a player selects a morph, a GUI shows up that lets them change the morph's expression/pose/whatever. I refer to them as Animations. Once I started using FilteringEnabled, the character animations are only seen by the client. I was wondering why this was happening and how I can change it. Here's an example of the scripts I've been using (both are in local scripts):

playerman = script.Parent.Parent.Parent.Parent.Parent.Character
function change()
playerman.Chest.Smile.Transparency=0
playerman.Chest.Frown.Transparency=1
wait()
script.Parent.t.Disabled = false
script.Disabled = true
end

script.Parent.MouseButton1Click:connect(change)

If the button is pressed again, it will put the morph back to its neutral state.

playerman = script.Parent.Parent.Parent.Parent.Parent.Character
function change()
playerman.Chest.Smile.Transparency=1
playerman.Chest.Frown.Transparency=0
wait()
script.Parent.e.Disabled = false
script.Disabled = true
end

script.Parent.MouseButton1Click:connect(change)

I've been trying to fix this for so long, but I can't come up with a solution.

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You today are going to learn to use RemoteEvents~

Okay, so for starters, it's only on the client side because it's a LOCAL script, meaning it'll only happen locally. To make it Server-side you'll have to make a Serverscript that catches the event. It's a little more code but worth it in the end. :P

-- Note: Put this script inside the ScreenGui, not the Buttons themselves.
-- ClientSideScript

-- || Services ||
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- || Variables ||
local AnimationRemote = ReplicatedStorage:WaitForChild("AnimationRemote")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local SmileButton -- = ButtonPathHere
local FrownButton -- = ButtonPathHere

-- || EventTriggerer ||
SmileButton.MouseButton1Click:connect(function()
AnimationRemote:FireServer("Smile")
end)

FrownButton.MouseButton1Click:connect(function()
AnimationRemote:FireServer("Frown")
end)

So, we've just set up to make it so the Buttons trigger something called a RemoteEvent, now we just have to create that RemoteEvent so it doesn't error.

-- Note: Put this script inside of ServerScriptService
-- ServerSideScript

-- || Services ||
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- || Variables ||
local AnimationRemote = Instance.new("RemoteEvent", ReplicatedStorage) AnimationRemote.Name = "AnimationRemote"

-- || EventHandler ||
AnimationRemote.OnServerEvent:connect(function(Ply, Animation)
if Animation == "Smile" then
Ply.Character.Chest:FindFirstChild("Smile").Transparency = 0
Ply.Character.Chest:FindFirstChild("Frown").Transparency = 1
elseif Animation == "Frown" then
Ply.Character.Chest.FindFirstChild("Smile").Transparency = 1
Ply.Character.Chest:FindFirstChild("Frown").Transparency = 0
end
end)

Be sure to let me know if I missed something

So far, I've made the Client fire the event to the server, which makes the Player's Animation changed based on the button pressed!

If this doesn't work, let me know in a comment and I'll edit the code.

Filtering Enabled

RemoteEvents/RemoteFunctions

Best of luck!

0
Thank you so much for answering! However, the script only partly works. Perhaps I'm doing something wrong... I'm able to change the morph to make it smile, but I can't make it go back to its frown expression (which is its neutral face) snarns 25 — 7y
0
To help clarify something for me, if I click the Smile Button to make my character smile, is this scripted in a way where I have to click the same button again to change the expression back to its neutral state. Or do I have to make a separate button for that? snarns 25 — 7y
0
Can you show me the scripts called: t and e? Vingam_Securis 213 — 7y
0
Those are the ones posted in the question I asked. The first one is e, second is t. snarns 25 — 7y
View all comments (5 more)
0
Mmmm, they shouldn't disable each other. Because they can't enable themselves. Vingam_Securis 213 — 7y
0
Oh! I've figured out the problem! On line 16 of the second script you showed me it should be [Ply.Character.Chest:] but you put a period instead of a colon. It works now! snarns 25 — 7y
0
Alright so I managed to make it work when I'm in develop mode, but when I actually play my game it doesn't work at all. Any idea why that's happening? snarns 25 — 7y
0
FilteringEnabled isn't Enabled in Develop. Vingam_Securis 213 — 7y
0
So how do I make this work in my game when I'm not using Develop? snarns 25 — 7y
Ad

Answer this question