type PayloadResponse = {
Success: number,
Message: string?,
Payload: any?
}
type VoteResults = {
Red: {
Count: number?,
Players: {number}
},
Green: {
Count: number?,
Players: {number}
}
}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local VotingRemoteFunction = ReplicatedStorage.VotingRemoteFunction
local VotingRemoteEvent = ReplicatedStorage.VotingRemoteEvent
You don't really need the remote event, but it can be used if you need it.
The remote event only has one event at the moment, and that is whenever the current vote ends. Please note that this will only be emitted to the player that caused the vote to start in the first place.
An example:
local VotingRemoteEvent = ReplicatedStorage:WaitForChild("VotingRemoteEvent")
VoitingRemoteEvent.OnClientEvent:Connect(function(Event)
if Event == "VoteEnded" then
-- whatever
end
end)
This allows you to call all of the supported methods of the backend system like starting votes, etc.
An example:
local VotingRemoteFunction = ReplicatedStorage:WaitForChild("VotingRemoteFunction")
local Result = VotingRemoteFunction:InvokeServer('event', payload)
if Result.Success then
local Payload = Result.Payload
-- whatever
else
error(Result.Message)
end
Event is obviously the name of the event, payload is the event's parameter.
All methods return a PayloadResponse
, the fields are self explanatory.
--// *Name* -> Payload Response | Expected Payload | Method Description |
--// ------------------------------------ | -------------------------- | ------------------------------------- |
--// StartVote -> RemoteEvent | Payload: { Time: number? } | Start a vote. |
--// EndVote -> nil | Payload: nil | End the current running vote. |
--// GetResults -> VoteResults | Payload: nil | Get current vote results. |
--// ClearResult -> nil | Payload: nil | Clear current vote results. |
--// GetIsVoteRunning -> boolean | Payload: nil | Check if a vote is currently running. |
Here is an example when starting a vote:
local Remote : RemoteFunction = game:GetService("ReplicatedStorage"):WaitForChild("VotingRemoteFunction")
print(Remote:InvokeServer("StartVote", { Time = 2 * 60 }))
- If no time is specified, you will need to call
EndVote
in order for the vote to end. If you don't want to pass a time, pass time asnil
or just pass an empty table. - Anyone in studio can use the system, in-game, only dyna can.
- Clear results, and get results can be executed at any time, even if a vote is ongoing/not happening.
- Vote results are only cleared when a vote is started or when
ClearResults
is called. - You can use the RemoteEvent returned by the
StartVote
to know when the vote is over. It's the same instance asVotingRemoteEvent
.
Let me know if you have any questions. :)