Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a voting system that gives players a gear?

Asked by 3 years ago

Hello. I am currently working on a story type game. I am making a script where you vote for what item you want to use. This is the main script, and what I have currently.

local togglePollEvent = game.ReplicatedStorage.Remotes.togglePollEvent

wait(5)

togglePollEvent:FireAllClients(true)

wait(15)

togglePollEvent:FireAllClients(false)

wait(1)

if game.ReplicatedStorage.Poll.Option1.Value >= game.ReplicatedStorage.Poll.Option2.Value then

local AssetId = 21392199 -- paste the gear ID here

local Model = game:GetService("InsertService"):LoadAsset(AssetId)

local Tool = Model:GetChildren()
Tool.Parent = game.StarterPack

elseif game.ReplicatedStorage.Poll.Option1.Value < game.ReplicatedStorage.Poll.Option2.Value then

local AssetId = 10472779 -- paste the gear ID here

local Model = game:GetService("InsertService"):LoadAsset(AssetId)

local Tool = Model:GetChildren()
Tool.Parent = game.StarterPack

end

As you can see, there are two options. If one is selected it should give you the gear for which ever option has the most votes. But sadly, It does not work. Does anyone know a way for the game to give ALL players gear once the option wins! Please, :D

Note - Everything in the script and gui is all working, I just need the gear to be given.

1 answer

Log in to vote
0
Answered by 3 years ago

Use Model:FindFirstChildOfClass("Tool") or similar instead of GetChildren() when assigning Tool as you're getting an array of children instead of the one you want, you can add it to StarterPack like your doing if you want players to respawn with the gear then you could loop through the players to add it to their backpacks like this

for i,ply in ipairs(game:GetService("Players"):GetChildren()) do
    local clone = Tool:Clone()
    clone.Parent = ply.Backpack
end

I recommend using a function that parses an AssetId instead of repeating the code

Ad

Answer this question