VotekickScript not working nor sending errors

I was working on a votekick system, but for some reason when I try it with multiple players, it doesnt send an error, yet does nothing, heres my script:

local adminList = {} --Players that can instantly votekick.

local prefix = "!" --If the message the player sent starts with this, it means that they want to send a command

local function getPlayerFromPartialName(PartialName)
	local foundName = nil
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local PossiblePlayer = Players[i]
		if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then
			foundName = PossiblePlayer
		end
	end

	if not foundName then
		return nil
	else
		return foundName
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(command)
		if game.ReplicatedStorage.VotekickValues.VotekickInProgress == false then
			local msg = command:lower()
			local targetSplit = msg:split(" ")
			local cmd = targetSplit[1]
			local target = targetSplit[2]
			if target == nil or cmd == nil then
				print("returned")
				return nil
			else
				print("continued")
			end
			print(cmd)
			print(target)
			local prefixCut = cmd:split(prefix)
			print(prefixCut[2])
			if prefixCut[2] == "votekick" then
				print("worked")
			else
				print("command wasnt initiated")
				return
			end
			local target = getPlayerFromPartialName(target)
			print(target)
			if target then
				print(true)
			else
				print(false)
				return
			end
			print(target)
			print(target.Name)
			local votes = 1
			local requiredVotes = math.round(math.min(1,#game.Players:GetPlayers() * .65))
			for i,v in pairs(game.Players:GetPlayers()) do
				local gui = v.PlayerGui:FindFirstChild("VotekickGui")
				gui.Enabled = true
				if not gui or v == target then
					gui.Enabled = false
				end
				gui.Frame.TextLabel.Text = "A votekick was initiated for "..target.DisplayName.." (@"..target.Name..")"
				local votecasted = false
				local yes = gui.Frame:WaitForChild("Yes")
				local no = gui.Frame:WaitForChild("No")

				yes.MouseButton1Up:Connect(function()
					if votecasted == false then
						votes += 1
						gui.Enabled = false
						votecasted = true
					end
				end)
				no.MouseButton1Up:Connect(function()
					gui.Enabled = false
				end)
			end
			task.wait(5)
			if votes >= requiredVotes then
				target:Kick()
			end
		end
	end)
end)

Help is appriciated!

Edit: Heres the explorer:
image

Why is foundName = nil?
Not sure what else is causing the problem, looks flawless to me

My issue is that it prints nothing, doesnt give any errors, and it does nothing.

Though the function gives back a player even without full username (Example: if I want to get Shedletsky, I can do shed instead of the full username.)

Okay I’m not sure then. It looks flawless to me. Maybe try rewriting the formation

I found something weird, when I removed the if statement, which is the if game.ReplicatedStorage.VotekickValues.VotekickInProgress == false then, it worked, but I want to keep it though just incase 2 votekicks occur.

I kept it false when I started the game though.

What are the properties of VotekickInProgress?

image

What about VotekickValues???

It appears fine, maybe I just need to look at the if statement?

image

I guess… Try testing different things with the if statement, removing parts and see if you get any results

I found it, I need to do VotekickInProgress.Value == false,

Incorrect: if game.ReplicatedStorage.VotekickValues.VotekickInProgress == false then
Correct: if game.ReplicatedStorage.VotekickValues.VotekickInProgress.Value == false then

1 Like

OHHHHHH Niceeee! So it all works fine now?

Yep! I’ll fix the part where the player who initiated the votekick wont get the Gui now.

Great! Glad I couldn’t help lol