if msg == "yes" then -- Thing i'm trying to change to a ui click
print("what")
if plrsVoted[plr] ~= "yes" then
votesForKick = votesForKick + 1
end
plrsVoted[plr] = "yes"
elseif msg == "no" then -- Thing i'm trying to change to a ui click
print("what")
if plrsVoted[plr] == "yes" then
votesForKick = votesForKick - 1
end
plrsVoted[plr] = "no"
end
end
end)
end)
Are you able to use two gui text buttons to work as yes and no? Here’s how I would implement it using two buttons named “yes” and “no” (with their text saying the respective word), which are siblings to a localscript parented to a frame, containing the following:
Alternatively, if this needs to be done on the server (since it looks like there’s a table of voters) you’d use the same button setup and have it fire a boolean at the server using a remote event.
local votekickCmd = "!votekick"
local cooldown = 60
local plrsOnCooldown = {}
local timeForVote = 10
local isVotingForKick = false
local plrsVoted = {}
local votesForKick = 0
local systemMsgRE = game.ReplicatedStorage["Other Remotes"]:WaitForChild("Votekick")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.sub(msg, 1, string.len(votekickCmd)) == votekickCmd and not isVotingForKick then
local plrVoted = game.Players:FindFirstChild(string.sub(msg, string.len(votekickCmd) + 2))
if plrVoted and not plrsOnCooldown[plr] then
plrsOnCooldown[plr] = true
isVotingForKick = true
votesForKick = 0
systemMsgRE:FireAllClients(plrVoted, plr)
wait(timeForVote)
isVotingForKick = false
if votesForKick >= math.ceil(#game.Players:GetPlayers()/2) then plrVoted:Kick("You have been votekicked") end
wait(cooldown - timeForVote)
plrsOnCooldown[plr] = nil
end
elseif isVotingForKick then
if msg == "yes" then
print("what")
if plrsVoted[plr] ~= "yes" then
votesForKick = votesForKick + 1
end
plrsVoted[plr] = "yes"
elseif msg == "no" then
print("what")
if plrsVoted[plr] == "yes" then
votesForKick = votesForKick - 1
end
plrsVoted[plr] = "no"
end
end
end)
end)```
local votekickCmd = "!votekick"
local cooldown = 60
local plrsOnCooldown = {}
local timeForVote = 10
local isVotingForKick = false
local plrsVoted = {}
local votesForKick = 0
local systemMsgRE = game.ReplicatedStorage["Other Remotes"]:WaitForChild("Votekick")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.sub(msg, 1, string.len(votekickCmd)) == votekickCmd and not isVotingForKick then
local plrVoted = game.Players:FindFirstChild(string.sub(msg, string.len(votekickCmd) + 2))
if plrVoted and not plrsOnCooldown[plr] then
plrsOnCooldown[plr] = true
isVotingForKick = true
votesForKick = 0
systemMsgRE:FireAllClients(plrVoted, plr)
wait(timeForVote)
isVotingForKick = false
if votesForKick >= math.ceil(#game.Players:GetPlayers()/2) then plrVoted:Kick("You have been votekicked") end
wait(cooldown - timeForVote)
plrsOnCooldown[plr] = nil
end
elseif isVotingForKick then
plr.PlayerGui.Votekick.Yes.Activated:connect(function()
print("yes")
votesForKick += 1
plrsVoted[plr] = "yes"
end)
plr.PlayerGui.Votekick.No.Activated:connect(function()
print("no")
votesForKick -= 1
plrsVoted[plr] = "no"
end)
end
end)
end)```
^ My current script
nothing printing so far
Looks like you’d need to separate the statement under “elseif isVotingForKick” into its own function, bound to a remote event. Try removing that portion and adding this to the server script, somewhere outside of the PlayerAdded function:
local voteEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
voteEvent.Name = "voteEvent"
voteEvent.OnServerEvent:connect(function(plr, vote)
if isVotingForKick then
if vote=="yes" then
print(plr.Name .. " voted yes!")
votesForKick += 1
plrsVoted[plr] = "yes"
elseif vote=="no" then
print(plr.Name .. " voted no!")
votesForKick -= 1
plrsVoted[plr] = "no"
else--Incase vote is nil or anything other than yes/no, catch the error, just for debug purposes:
print(plr.Name .. " voted... neither???")
end
else
print("not currently voting...")
end
end)
Then, change my localscript code from above to the following:
local votekickCmd = "!votekick"
local cooldown = 60
local plrsOnCooldown = {}
local timeForVote = 5
local isVotingForKick = false
local plrsVoted = {}
local votesForKick = 0
local systemMsgRE = game.ReplicatedStorage["Other Remotes"]:WaitForChild("Votekick")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.sub(msg, 1, string.len(votekickCmd)) == votekickCmd and not isVotingForKick then
local plrVoted = game.Players:FindFirstChild(string.sub(msg, string.len(votekickCmd) + 2))
if plrVoted and not plrsOnCooldown[plr] then
plrsOnCooldown[plr] = true
isVotingForKick = true
votesForKick = 0
systemMsgRE:FireAllClients(plrVoted, plr)
wait(timeForVote)
isVotingForKick = false
if votesForKick >= math.ceil(#game.Players:GetPlayers()/2) then plrVoted:Kick("You have been votekicked") end
wait(cooldown - timeForVote)
plrsOnCooldown[plr] = nil
end
elseif isVotingForKick then
local voteEvent = game.ReplicatedStorage["Other Remotes"]:WaitForChild("Vote")
voteEvent.OnServerEvent:connect(function(plr, vote)
if isVotingForKick then
if vote=="yes" then
print(plr.Name .. " voted yes!")
votesForKick += 1
plrsVoted[plr] = "yes"
elseif vote=="no" then
print(plr.Name .. " voted no!")
votesForKick -= 1
plrsVoted[plr] = "no"
else--Incase vote is nil or anything other than yes/no, catch the error, just for debug purposes:
print(plr.Name .. " voted... neither???")
end
else
print("not currently voting...")
end
end)
end
end)
end)
Move my snippet of code outside of the game.Players.PlayerAdded… function, somewhere say, right below the line “local systemMsgRE = …”. Since right now, isVotingForKick = false, so that portion of the code won’t execute, and the event won’t be made/bound.
I realize now this may mean a total rewrite of how this is server script is structured. If it’s still trouble, I can help rewrite some of it.