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

how do i create a gui that counts how many players are in one place?

Asked by 4 years ago
Edited 4 years ago

I want to make a GUI that will count how many players are sitting in a truck for my Story game's lobby. When I step on a button, it will put me in the truck but I don't know how to make the number larger on the SurfaceGUI I made according to how many people are sitting in the truck. Here is what I have done so far

--Variables
local leftValue = game.Workspace.LeftRoad.Truck.Value --To see if the truck exists in the Workspace
local CounterLeft = game.Workspace.Counters.LeftCounter.SurfaceGui.Count.Text
local LeftCountVal = game.Workspace.LeftRoad.Count.Value
local buttonLeft = game.Workspace.Entries.LeftEnter --Button when touched, makes you enter the truck

--Script to count players in the truck
if leftValue == true then
    buttonLeft.Touched:Connect(function(plr)
        if plr.Parent:FindFirstChild("Humanoid") then
            LeftCountVal = LeftCountVal +1
            wait(0.5)
            CounterLeft = LeftCountVal
        end
    end)
end

So I want the text on the SurfaceGui to be the same as the text on the IntValue (Which is the variable "LeftCountVal") some help would be greatly appreciated!

1 answer

Log in to vote
0
Answered by 4 years ago

Problem

You are storing game.Workspace.Counters.LeftCounter.SurfaceGui.Count.Text and game.Workspace.LeftRoad.Count.Value in a Variable. But when you try to change it it ONLY changes that variable, NOT the property itself.

Solution

  1. Instead of Storing the Property store the Object (The TextLabel and Value)
  2. When setting the Value or Text add .PropertyName after the Variable.

Final Script

--Variables
local leftValue = game.Workspace.LeftRoad.Truck.Value --To see if the truck exists in the Workspace
local CounterLeft = game.Workspace.Counters.LeftCounter.SurfaceGui.Count
local LeftCountVal = game.Workspace.LeftRoad.Count
local buttonLeft = game.Workspace.Entries.LeftEnter --Button when touched, makes you enter the truck

--Script to count players in the truck
if leftValue == true then
    buttonLeft.Touched:Connect(function(plr)
        if plr.Parent:FindFirstChild("Humanoid") then
            LeftCountVal.Value = LeftCountVal.Value +1
            wait(0.5)
            CounterLeft.Text = LeftCountVal.Value
        end
    end)
end
0
Thanks a lot for this advice. I also had a problem with it counting too many people when only one steps on the button but i figured it out. I just needed a debounce. kingblaze_1000 359 — 4y
0
no problem Luka_Gaming07 534 — 4y
0
Can you mark this as Answered? Luka_Gaming07 534 — 4y
Ad

Answer this question