Hello, so I was wondering how do I make this script only work when a user has a certain gamepass?
--[ SERVICES ]--
local Players = game:GetService("Players")
--[ MAIN LOCALS ]--
local PlayerUsage = {} -- Player Table
local syncthing = "/sync ([%w_]+)" --this is a string pattern that should match any player username
local leavesync = "/leavesync" -- string for leaving the sync
--[ FUNCTIONS ]--
game.Players.PlayerAdded:Connect(function(localplr)
localplr.Chatted:Connect(function(msg)
--[{ JOINSYNC }]--
local subjectName = msg:match(syncthing) -- checking to see if it matches text
if subjectName then
local subject = game.Players:FindFirstChild(subjectName)
if subject then
-- play animation
local humanoid = localplr.Character:WaitForChild("Humanoid") -- player humanoid
local humanoid2 = subject.Character:WaitForChild("Humanoid") -- subject humanoid
local animator = humanoid:WaitForChild("Animator") -- player animator
local animator2 = humanoid2:WaitForChild("Animator") -- subject animator
local AnimationTracks = animator2:GetPlayingAnimationTracks() -- subject animation tracks
for _, v in pairs(AnimationTracks) do
local track = animator:LoadAnimation(v.Animation) -- requires an animation object
track.Priority = Enum.AnimationPriority.Action
track:Play()
track.TimePosition = v.TimePosition
track:AdjustSpeed(v.Speed)
end
end
end
--[{ LEAVESYNC }]--
local leaveName = msg:match(leavesync) -- checking to see if it matches text
if leaveName then
-- stop animation
local humanoid = localplr.Character:WaitForChild("Humanoid") -- player humanoid
local animator = humanoid:WaitForChild("Animator") -- player animator
local AnimationTracks = animator:GetPlayingAnimationTracks() -- player animation tracks
for _,v in pairs(AnimationTracks) do
v:Stop()
end
end
end)
end)
--[[ SYNC FUNCTION ]]--
local function sync(player, player2)
local animator1 = player.Character:WaitForChild("Humanoid"):WaitForChild("Animator") -- Animator 1
local animator2 = player2.Character:WaitForChild("Humanoid"):WaitForChild("Animator") -- Animator 2
for _,v in pairs(animator2:GetPlayingAnimationTracks()) do
local track = animator1:LoadAnimation(v.Animation) -- Loading Animation
track.Priority = Enum.AnimationPriority.Action -- Setting Priority
track:Play() -- Playing animation
track.TimePosition = v.TimePosition -- Adjusting Time
track:AdjustSpeed(v.Speed) -- Adjusting Speed
end
end
--[[ EVENT FUNCTION ]]--
game.ReplicatedStorage.Sync.OnServerEvent:Connect(function(player, player2)
if player2 and player2:IsA("Player") then
local now = tick()
local LastUsed = PlayerUsage[player] or 0
if now - LastUsed > 3 then
PlayerUsage[player] = now
sync(player,player2)
end
end
end)