I have created a gamepass, that allows you to get a kick ability, which is usually disabled, that allows you to kick someone out of the game, if you kill them using the kick attack. The problem is, it keeps saying there is an infinite yield on LocalHamonKick, which is a local script stored in the Player’s backpack. Here is the script, and the explorer.
game.Players.PlayerAdded:Connect(function(plr)
local bp = plr:WaitForChild("Backpack")
local mps = game:GetService('MarketplaceService')
if mps:UserOwnsGamePassAsync(plr.UserId, 23171784) then
if plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true == false then
print("active")
bp:WaitForChild("LocalHamonKick").Disabled = false
local ss = game.ServerScriptService
ss.HamonKickServer.Disabled = false
elseif plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true then
print("deactive")
bp:WaitForChild("LocalHamonKick").Disabled = false
local ss = game.ServerScriptService
ss.HamonKickServer.Disabled = false
end
end
end)
Okeh. Would this work? I’m developing this on a group game, so I don’t have the gamepass, and the person who usually does this testing is offline.
game.Players.CharacterAdded:Connect(function(plr)
local bp = plr:WaitForChild("Backpack")
local mps = game:GetService('MarketplaceService')
if mps:UserOwnsGamePassAsync(plr.UserId, 23171784) then
if plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true == false then
print("active")
bp.LocalHamonKick.Disabled = false
local ss = game.ServerScriptService
ss.HamonKickServer.Disabled = false
elseif plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true then
print("deactive")
bp.HamonKick.Disabled = false
local ss = game.ServerScriptService
ss.HamonKickServer.Disabled = false
end
end
end)
I really feel like there is more issues here than waiting for the items in the backpack. Considering you are disabling a ServerScriptService script, based on the state of a single player.
Your script should in in a script, not local script, and if it detects the player owns the gamepass, then you should move the ‘tool’ the kick thing, into the player’s backpack from ServerStorage.
local ServerStorage = game:GetService("ServerStorage")
local LocalHamonKick = ServerStorage:WaitForChild("LocalHamonKick")
function GiveKick(player)
local Backpack = player:WaitForChild("Backpack")
local MarketplaceService = game:GetService("MarketplaceService")
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 23171784) then
LocalHamonKick:Clone().Parent = Backpack
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
GiveKick(player)
end)
end)
local success,err = pcall(function()
MarketplaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) -- or try adding a return at the beginning of this if it wont work
end)
if success then
--code here
else
warn("Player Doesn't own Gamepass")
end
function GiveKick(player)
local Backpack = player:WaitForChild("Backpack")
local MarketplaceService = game:GetService("MarketplaceService")
local success,result = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, 23171784)
end)
if success then
if result == true then
LocalHamonKick:Clone().Parent = Backpack
else
--doesnt own
end
else
print(result) --result holds the error code
end
end