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

Remote event doesnt get activated through the type check in my script?

In this script I am trying to pass a RemoteEvent once you say "Hello" But nothing is working, and theres no errors.

Script:

local replicatedstorage = game:GetService("ReplicatedStorage")
local RemoteEventConnection = game.ReplicatedStorage:WaitForChild("CommissionTest")
local player = game.Players.LocalPlayer
local GamePassId = 6766156 -- Replace with your gamepass
local WhitelistUserIDs = { --Your PlayerId's here
	79523404,
	0,
	1,
	2
}

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, GamePassId) == true or table.find(WhitelistUserIDs, player.UserId) then
	print("First")
	function onChatted(message, player)
		if message == "Hello" and game.MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamePassId) then
			print("message sent")
			RemoteEventConnection:FireServer(GamePassId,WhitelistUserIDs)


		end
	end
end



game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(message) onChatted(message, player)
		
	end)
end)

2 comments

0

Is this a client script or a server script?

0

its from the client, he uses LocalPlayer in the first few lines

1 answer

✓ Accepted answer

don't really recommend using this from a local script, way more secure while checking on the server, also wouldn't need the remote.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService('MarketplaceService')
local RemoteEventConnection = ReplicatedStorage:WaitForChild("CommissionTest")
local player = game.Players.LocalPlayer
local GamePassId = 6766156
local WhitelistUserIDs = {
	79523404;
}

function onChatted(message)
	if message == "Hello" then
		print("message sent")
		RemoteEventConnection:FireServer(GamePassId, WhitelistUserIDs)
	end
end

-- makes sure you're allowed to use the command, this one check is enough. don't need to check again in function.
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamePassId) or table.find(WhitelistUserIDs, player.UserId) then
	player.Chatted:Connect(onChatted)
end

1 comment

0

thanks bro

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