How Would I Make this LoadScript Work

I need help with something- I want to make a script check if you own a badge and then load another script into workspace if you do own the badge, and then kick you if you do not own it. This is for a ‘challenge’ type game I am making.

I have not gotten any errors at all, but it just will not kick you for not owning the badge and will just load the script anyway.

I am a pretty average scripter and have little to no idea about what I am doing. I got some help from a friend on this script but they also had no idea so any help is appreciated!

(AND YES I did change the BadgeId in the actually script, and I made sure I did not own the badge before testing it.)

local BanSave = dss:GetDataStore("BanSave")
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124545440
local BanReason = "You need to finish the challenge first!"

game.Players.PlayerAdded:Connect(function(player)
	local IsBanned  = Instance.new("BoolValue")
	IsBanned.Name = "IsBanned"
	IsBanned.Parent = player
	local IsBanned = true
	
	local RetrievedData
	local Retrieved, failed = pcall(function()
		RetrievedData = BanSave:GetAsync(player.UserId, player.IsBanned.Value)
	end)
	
	if Retrieved then
		player.IsBanned.Value = RetrievedData
	end
	
	if BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
		player.IsBanned.Value = false
	end

	if player.IsBanned.Value == true then
		player:Kick(BanReason)
	elseif 
		player.IsBanned.Value == false then
		wait(0.2)
		local instert = game:GetService("InsertService"):LoadAsset(13732732878)
		instert.Parent = workspace
	end
end)

inside of

the var isBanned defined two times :

  • local IsBanned = Instance.new(“BoolValue”)

And 3 lines later:

  • local IsBanned = true

try changing the name of the first IsBanned to IsBannedInstanceValue for exemple.

idk if it will correct the issue, but it cost nothing to try :slight_smile:

1 Like

Also why do not kicking the player immediately without creating the boolValue instance and why storing the value in datastore? Do u really need them?
like that:

local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124545440
local BanReason = "You need to finish the challenge first!"

game.Players.PlayerAdded:Connect(function(player)

    if BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
		local instert = game:GetService("InsertService"):LoadAsset(13732732878)
		instert.Parent = workspace
    else
		player:Kick(BanReason)
	end
end)
1 Like

Thanks, that’s a way better idea. I’ll try that out.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.