How to make emotes script into a gamepass only?

Hey! This is my first post :smiley:
I’ll… just hand over the scripts to see how to implement a gamepass to it… Thanks!

Emote script (Module)

print("it's just a module to change what emote or sounds to play... if you need it, I'll send it...")

Emote script (Local)

-- basically this is for removing the "You can't use that Emote" thing
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Emote")
local remote2 = game:GetService("ReplicatedStorage"):WaitForChild("Emote Function")

local LocalPlayer = game:GetService("Players").LocalPlayer

remote.OnClientEvent:Connect(function(arg1,arg2,arg3,arg4,arg5)
	if arg1 == "Remove Message" then
		local chat = LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Chat").Frame.ChatChannelParentFrame.Frame_MessageLogDisplay.Scroller
		for i,v in pairs(chat:GetChildren()) do
			if v.Name == "Frame" and v.TextLabel.Text == arg2 then
				v:Destroy()
				break
			end
		end
	end
	if arg1 == "Create Mute Button" then
		local gui = Instance.new("ScreenGui",LocalPlayer:WaitForChild("PlayerGui"))
		gui.Name = "Mute"
		gui.ResetOnSpawn = false
		local button = Instance.new("TextButton",gui)
		button.Size = UDim2.new(0,112,0,50)
		button.Position = UDim2.new(0.01, 0,0.475, 0)
		button.BackgroundColor3 = Color3.fromRGB(203,203,0)
		button.BorderSizePixel = 2
		button.Font = Enum.Font.Fantasy
		button.Text = "Mute Emotes"
		button.TextSize = 18
		
		local muted = false
		button.MouseButton1Click:Connect(function()
			if not muted then
				muted = true
				button.Text = "Unmute Emotes"
				button.TextSize = 16
				for i,v in pairs(game:GetService("Players"):GetPlayers()) do
					local character = v.Character 
					if character then
						for i2,v2 in pairs(character:GetDescendants()) do
							if v2:IsA("Sound") and remote2:InvokeServer("Is Emote",v2) then
								v2.Volume = 0
							end
						end
					end
				end
			else
				muted = false
				button.Text = "Mute Emotes"
				button.TextSize = 18
				for i,v in pairs(game:GetService("Players"):GetPlayers()) do
					local character = v.Character 
					if character then
						for i2,v2 in pairs(character:GetDescendants()) do
							if v2:IsA("Sound") then
								local volume = remote2:InvokeServer("Get Volume",v2)
								if volume then
									v2.Volume = volume
								end
							end
						end
					end
				end
			end
		end)
		
		workspace.DescendantAdded:Connect(function(child)
			if child:IsA("Sound") then
				if remote2:InvokeServer("Is Emote",child) then
					child.Volume = 0
					child:GetPropertyChangedSignal("Volume"):Connect(function()
						if child.Volume > 0 and muted then
							child.Volume = 0
						end
					end)
				end	
			end
		end)
	end
end)

Emote script (server):


-- this is where I put the gamepass stuff in... I think I'm wrong tho...

local module = require(script.Parent)

local remote = game:GetService("ReplicatedStorage"):FindFirstChild("Emote")

local remote2 = game:GetService("ReplicatedStorage"):FindFirstChild("Emote Function")

local LocalPlayer = game:GetService("Players").LocalPlayer -- this and the next 2 lines are mine
local market = game:GetService("MarketplaceService")
local gamepass = market:UserOwnsGamePassAsync(715068423)

if not remote then
	remote = Instance.new("RemoteEvent")
    remote.Name = "Emote"
	remote.Parent = game:GetService("ReplicatedStorage")
end

if not remote2 then
	remote2 = Instance.new("RemoteFunction")
	remote2.Name = "Emote Function"
	remote2.Parent = game:GetService("ReplicatedStorage")
end

game:GetService("Players").PlayerAdded:Connect(function(player)
	local function end_current_sound()
		local character = player.Character
		if character and character:FindFirstChild("HumanoidRootPart") then
			for i,v in pairs(character.HumanoidRootPart:GetChildren()) do
				if v:IsA("Sound") then
					v.Playing = false
				end
			end
		end
	end
	
	player.Chatted:Connect(function(message)
		for i,v in pairs(module.animations) do
		    if message == v.command then
			    remote:FireClient(player,"Remove Message","You can't use that Emote.")
			    local character = player.Character
			    if character then
				    local humanoid = character:FindFirstChildOfClass("Humanoid")
					if humanoid then
						for i2,v2 in pairs(humanoid:GetPlayingAnimationTracks()) do
							v2:Stop()
						end
					    end_current_sound()
					    local animation = Instance.new("Animation")
	                    animation.AnimationId = v.animation_id
						local loadedanimation = humanoid:LoadAnimation(animation)
						loadedanimation:Play()
					    local sound = character.HumanoidRootPart[i]
					    sound.Playing = true
				    	local still_playing = true
					    local properties = {"Sit","Jump","MoveDirection"}
					    for i2,v2 in pairs(properties) do
						    humanoid:GetPropertyChangedSignal(v2):Connect(function()
								still_playing = false
								sound.Playing = false
								animation:Destroy()
								loadedanimation:Stop()
						    end)
						end
					    wait(loadedanimation.Length)
						if still_playing and v.animation_loops then
						    loadedanimation:Play()
						else
							animation:Destroy()
							loadedanimation:Stop()
							sound.Playing = false
							break
						end
				    end
				end
				break
			end
		end
	end)
	player.CharacterAdded:Connect(function(character)
		local new_script = script.Parent:WaitForChild("EmoteScript"):Clone()
		new_script.Parent = character
		for i,v in pairs(module.animations) do
		    local sound = Instance.new("Sound",character:WaitForChild("HumanoidRootPart"))
		    sound.Name = i
		    sound.SoundId = v.sound_id
		    sound.Volume = v.sound_volume
		    sound.RollOffMinDistance = v.sound_min_distance
		    sound.RollOffMaxDistance = v.sound_max_distance
		    if v.animation_loops then
			    sound.Looped = true
			end
		end	
	end)
	if module["Allow Muting"] then
		remote:FireClient(player,"Create Mute Button")
	end
end)

remote2.OnServerInvoke = function(invoker,arg1,arg2,arg3,arg4,arg5)
	if arg1 == "Is Emote" then
		for i,v in pairs(module.animations) do
			if i == tostring(arg2) then
				return true
			end
		end
		return false
	end
	if arg1 == "Get Volume" then
		if arg2 and arg2:IsA("Sound") then
			return arg2.Volume
		end
		return nil
	end
end

I know roughly how to do it, it’s just I don’t know WHERE to put it :stuck_out_tongue:
If I used the wrong tags, PLEASE tell me.
(main script made by 0xc0000e9)

1 Like

You can check if the player owns the gamepass (server-side script in ServerScriptService), and use a RemoteEvent to tell that client to enable emotes if they do (LocalScript in StarterPlayerScripts). You can use StarterGui’s SetCoreGuiEnabled function to enable or disable it.

You could also use this to manage your chat enable or disable, which looks a bit messy…

local sGui = game:GetService("StarterGui")
sGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
--the above line disables chat
1 Like

I think I may have not given enough clarity… Oops.
The script is designed to function completely on workspace… So it doesn’t require needing to be put in any place such as StarterPlayer. I removed the chat history, so is there anything I can remove to prevent clutter?

I don’t really understand what you mean. Can you give a bit more information overall?

1 Like

Screenshot 2024-02-11 213333

^ No chat history

Screenshot 2024-02-11 213522

^ functional in workspace

and, is there anything I can remove from the LocalScript?

I may be an idiot to not include this before but… This is how you play the animations:

Screenshot 2024-02-11 214734

fake /e commands. So real. Very original…

Oh, that won’t work at all. A LocalScript just won’t run under the workspace.

As for script optimisation, I’m not too sure.