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

[CLOSED] player.Chatted (with gamepass) doesn't work. How do i fix it?

Asked by 4 years ago
Edited 4 years ago

If you want to use a working version in your game, take this model: Chat For GUI [GAMEPASS VERSION]

I want to show a UI element when the player chats something and owns a gamepass. I've tried this script but doesn't seem to work. (I put this in a LocalScript in StarterGui and Script in workspace/ServerScriptService) Here's what happens: Click Here My problem seems to be (and I've tried without gamepass code) the player.Chatted.

    local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 9291233
local player = Players.LocalPlayer
local hasPass = false
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    game.Players.PlayerAdded:connect(function(plr)
        plr.Chatted:connect(function(msg)
            if msg == "#custom" then 
if hasPass == false then
MarketplaceService:PromptGamePassPurchase(player , gamePassID)
            else
script.Parent.Custom.CUSTOMIZE.Visible = not script.Parent.Custom.CUSTOMIZE.Visible
end
            end
        end)
    end)

I also tried

script.Parent.Custom.CUSTOMIZE.Visible = true

Nothing seems to work

0
please tell us what it's doing and what you want it to do. we cannot fix your script with just "i don't know how to fix it, help". zadobyte 692 — 4y
0
i want to show a ui element when the player chats something and owns a gamepass RedStoneDeveloper 12 — 4y
0
what is it doing instead? zadobyte 692 — 4y
0
nothing RedStoneDeveloper 12 — 4y
View all comments (3 more)
0
Here is what happens: https://streamable.com/3r8i1d RedStoneDeveloper 12 — 4y
0
try "script.Parent.Custom.CUSTOMIZE.Visible = false" matiss112233 258 — 4y
0
y RedStoneDeveloper 12 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

I think I see a few errors.

1) You can't use LocalPlayer inside of a ServerScript as it doesn't run on the client.

  • If you are using a ServerScript

2) You can't use game.Players.PlayerAdded inside of a LocalScript as the script doesn't run, because the script will first initialize upon being loaded into the game.

  • If you are using a LocalScript

How To Fix This Problem

Use a ServerScript and get the player from when they added instead of using LocalPlayer.


Fixed Script

  • ServerScript Inside of ServerScriptService
local MPS = game:GetService("MarketPlaceService")
local passId = 9291233

game.Players.PlayerAdded:Connect(function(player)
    local hasPass = MPS:UserOwnsGamepassAsync(player.UserId, passId)
    player.Chatted:Connect(function(msg)
        if string.match(msg, "#custom", 1) then
            if hasPass == true then
                local pGui = player:WaitForChild("PlayerGui")
                local acG = pGui:WaitForChild("Name_Of_Screen_GUI_Here")
                acG.Custom.CUSTOMIZE.Visible = false --// Change This To The Directory Of The GUI Item You Want To Make It Non-Visible
            else
                MPS:PromptGamePassPurchase(player, passId)
            end
        end
    end)
end)

Hope this helped! If you need an explanation or if this doesn't work, let me know!

Ad
Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

Try pcalling this line

hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)

Use this site as a guide: https://developer.roblox.com/en-us/articles/Game-Passes-One-Time-Purchases

0
not what I'm looking for RedStoneDeveloper 12 — 4y
Log in to vote
0
Answered by 4 years ago

I figured it out! ServerScriptService (Script)

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if string.match(msg, "Message", 1) then
game.ReplicatedStorage.RemoteEvent:FireClient(player)
        end
    end)
end)

and StarterGui (LocalScript)

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 9291233 

    local player = Players.LocalPlayer
    local hasPass = false
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)

    if hasPass == true then
--What to do when chatted and owned
    else
        MarketplaceService:PromptGamePassPurchase(player, gamePassID)
    end
end)

And a RemoteEvent it Replicated Storage

Thanks to killerbrenden for the help!

Answer this question