Currently trying to make a script that when it detects that a player has all 3 checks as false it kicks them from the game or if the player has one of the 3 checks it prompts them with a purchase to an item. The player isn’t being detected, errors like “attempt to index nil with kick” or the function not being ran at all are the main errors. Tried removing players.playeradded and just putting a normal function however that’s when the 2 errors above come in, and if I leave it as is the function doesn’t get triggered(the script is being enabled by another script). The goal is to make this script server sided, Any help would be appreciated.
Code:
local Players = game:GetService("Players")
while true do
wait(5)
print("ok")
function Check(player)
print("In Check Function")
if CheckV == true then
MarketplaceService:PromptPurchase(player, ITEM_ID)
BindE:Fire()
print("Read... \n Continuing")
end
if CheckV2 == true then
MarketplaceService:PromptPurchase(player, ITEM_ID2)
end
if CheckV3 == true then
MarketplaceService:PromptPurchase(player, ITEM_ID3)
end
if CheckV == false and CheckV2 == false and CheckV3 == false then
print("Kick Detected")
player:Kick("You Do Not Own Any Items From The Event")
end
end
Players.PlayerAdded:Connect(Check)
end
You’re creating another event every 5 seconds, because your call to Connect is inside the loop, probably not what you want. I don’t see CheckV CheckV2 or CheckV3 defined anywhere.
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local BindE = game.ServerStorage.Purchase
local BindE2 = game.ServerStorage.Purchase2
local BindE3 = game.ServerStorage.Purchase3
local CheckV = game.ServerStorage.Check1.Value
local CheckV2 = game.ServerStorage.Check2.Value
local CheckV3 = game.ServerStorage.Check3.Value
local Check = game.ServerStorage.Check1
local Check2 = game.ServerStorage.Check2
local Check3 = game.ServerStorage.Check3
local ITEM_ID = 2598774005 --offered item
local ASSET_ID = 9255011 --owned item
local ASSET_NAME = "Silverthorn Antlers" --owned item name
local ITEM_ID2 = 25987754005 --offered item
local ASSET_ID2 = 9255011 --owned item
local ASSET_NAME2 = "Silverthorn Antlers" --owned item name
local ITEM_ID3 = 25987748005 --offered item
local ASSET_ID3 = 9255011 --owned item
local ASSET_NAME3 = "Silverthorn Antlers" --owned item name
Ignore that the same asset id is used 3 times that was for testing
This will only check the Value once. If the Value changes, CheckV will not change. You need to move the access of Value to the point in time where you actually want to check it.
So I would also put that in the loop? and what about the function(player) error is there an alternative where I can prompt the purchase and not have to connect player to the function?
my last question is the kick player line won’t work because of the error "“attempt to index nil with kick”
is there a way around that or is it impossible to keep it all server sided
There are plenty of mistakes in your code boo, you’re placing the check function inside the while true do loop, your code is missing MarketplaceService reference, undefined variables: CheckV, CheckV2, and CheckV3 are not defined, missing ITEM_ID and ITEM_ID2 variables, try this code and make sure to replace the placeholders (ITEM_ID , ITEM_ID2 , etc.) with the actual values you need. Also remember to define and assign values to CheckV , CheckV2 , and CheckV3 appropriately Xx
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ITEM_ID = ID
local ITEM_ID2 = ID
function Check(player)
local CheckV =
local CheckV2 =
local CheckV3 =
if CheckV then
MarketplaceService:PromptPurchase(player, ITEM_ID)
BindE:Fire()
end
if CheckV2 then
MarketplaceService:PromptPurchase(player, ITEM_ID2)
end
if CheckV3 then
MarketplaceService:PromptPurchase(player, ITEM_ID3)
end
if not CheckV and not CheckV2 and not CheckV3 then
player:Kick("You Do Not Own Any Items From The Event")
end
end
Players.PlayerAdded:Connect(Check)
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local BindE = game.ServerStorage.Purchase
local BindE2 = game.ServerStorage.Purchase2
local BindE3 = game.ServerStorage.Purchase3
local CheckV = game.ServerStorage.Check1.Value
local CheckV2 = game.ServerStorage.Check2.Value
local CheckV3 = game.ServerStorage.Check3.Value
local Check = game.ServerStorage.Check1
local Check2 = game.ServerStorage.Check2
local Check3 = game.ServerStorage.Check3
local ITEM_ID = 2598774005 --offered item
local ASSET_ID = 9255011 --owned item
local ASSET_NAME = "Silverthorn Antlers" --owned item name
local ITEM_ID2 = 25987754005 --offered item
local ASSET_ID2 = 9255011 --owned item
local ASSET_NAME2 = "Silverthorn Antlers" --owned item name
local ITEM_ID3 = 25987748005 --offered item
local ASSET_ID3 = 9255011 --owned item
local ASSET_NAME3 = "Silverthorn Antlers" --owned item name
Make sure to replace the placeholder values (ITEM_ID, ASSET_ID, etc.) with the actual values you need babes
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local BindE = game.ServerStorage.Purchase
local BindE2 = game.ServerStorage.Purchase2
local BindE3 = game.ServerStorage.Purchase3
local CheckV = game.ServerStorage.Check1.Value
local CheckV2 = game.ServerStorage.Check2.Value
local CheckV3 = game.ServerStorage.Check3.Value
local Check = game.ServerStorage.Check1
local Check2 = game.ServerStorage.Check2
local Check3 = game.ServerStorage.Check3
local ITEM_ID = 2598774005
local ASSET_ID = 9255011
local ASSET_NAME = "Silverthorn Antlers"
local ITEM_ID2 = 25987754005
local ASSET_ID2 = 9255011
local ASSET_NAME2 = "Silverthorn Antlers"
local ITEM_ID3 = 25987748005
local ASSET_ID3 = 9255011
local ASSET_NAME3 = "Silverthorn Antlers"
function Check(player)
print("In Check Function")
if CheckV then
MarketplaceService:PromptPurchase(player, ITEM_ID)
BindE:Fire()
print("Read... \n Continuing")
end
if CheckV2 then
MarketplaceService:PromptPurchase(player, ITEM_ID2)
BindE2:Fire()
print("Read... \n Continuing")
end
if CheckV3 then
MarketplaceService:PromptPurchase(player, ITEM_ID3)
BindE3:Fire()
print("Read... \n Continuing")
end
if not CheckV and not CheckV2 and not CheckV3 then
print("Kick Detected")
player:Kick("You Do Not Own Any Items From The Event")
end
end
Players.PlayerAdded:Connect(Check)
those are temporary for testing, I put them all the same to see if it would prompt the purchase, the main error is the function sending back attempted to index nil with kick. For some reason it doesn’t recognize I’m a player
didn’t work, got completely ignored, I tried removing the entire connect thing and just putting Check(Players), which shot back the same error of attempting to index nil with kick