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

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

Asked by 2 years ago

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)
0
Is this a client script or a server script? cracker_555555555555 0 — 2y
0
its from the client, he uses LocalPlayer in the first few lines BulletproofVast 1033 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

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
0
thanks bro snipperdiaper 120 — 2y
Ad

Answer this question