Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

7 comments

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".

0

i want to show a ui element when the player chats something and owns a gamepass

0

what is it doing instead?

0

nothing

0

Here is what happens: https://streamable.com/3r8i1d

0

try "script.Parent.Custom.CUSTOMIZE.Visible = false"

0

y

3 answers

✓ Accepted answer

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!

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!

2 comments

0

No problem! Glad to help! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.