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

Why doesn't the if statement results in 'false' when a player doesn't have the gamepass?

Asked by 3 years ago

While making a game, I tried making a gamepass that would allow players to chat in the multiplayer version of the game, and for some strange reason; it doesn't end up as 'false' when the player doesn't have the gamepass, which begs the question: Why isn't this working?

Heres the code:

local ServerScriptService = game:GetService("ServerScriptService")

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Channel = ChatService:GetChannel("All")
local MarketplaceService = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(plr)
    if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, 14986576) then
        print("Allowed player " .. plr.Name .. " to chat.")
    else
        Channel:MuteSpeaker(plr.Name, "You are not permitted to chat, Boss's orders.", 0)

        script:FindFirstChild("Placeholder"):Clone().Parent = plr.PlayerGui
    end
end)

Here is the game incase you want to see the multiplayer mode. A gui should appear, notifying the player that they do not have the gamepass, and should mute the player's speaker.

Answer this question