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

I added a function to my script and It's broken now. There are no errors. How do I fix it?

Asked by 5 years ago
--// DECLARING VARIABLES \\--

local textBox = game.StarterGui.Events.Event
local textValue = game.StarterGui.Events.Value.Value
local toolGive = game:WaitForChild("ReplicatedStorage").Tool1:Clone()
local teamsService = game:GetService("Teams")
local playersService = game:GetService("Players")

--// STARTING \\--

playersService.PlayerAdded:Connect(function(player)

textBox.Text = textValue

while true do
    textBox.Text = textValue
    textValue = "Free Time"
    wait(1)
    textBox.Text = textValue
    textValue = "Testing Time"
    wait(1)
    textBox.Text = textValue
    textValue = "Riot Time"
    if player.Team.Name == "Team 1" then
        toolGive.Parent = player:WaitForChild("Backpack")
    end
    wait(1)
end

end)

I made this script and I had to access the LocalPlayer and this is not a localscript, so I decided to make the function game.Players.PlayerAdded:Connect(function(player) , but after I did that nothing was working.

0
Is it because I'm using a loop inside a function? darieus887 -3 — 5y
0
You're using StarterGui instead of PlayerGui. Modifying StarterGui will only change the gui for players who come after you change it. hiimgoodpack 2009 — 5y

1 answer

Log in to vote
0
Answered by
Time_URSS 146
5 years ago
Edited 5 years ago

Issue 1: In a local Variable, if we want to change the Value of a ValueObject we NEVER use the .Value property in a variable. Instead, the .Value property should be used later, as I state below:

Issue 2: We don't use a string to change teams, the preferred way is to use game:GetService("Teams") and the team name here. There are some times that it won't work using a string.

--// DECLARING VARIABLES \\--

local textBox = game.StarterGui.Events.Event
local textValue = game.StarterGui.Events.Value -- We don't use the .value property here, we set the value object so we can change the value later
local toolGive = game:WaitForChild("ReplicatedStorage").Tool1:Clone()
local teamsService = game:GetService("Teams")
local playersService = game:GetService("Players")

--// STARTING \\--

playersService.PlayerAdded:Connect(function(player)
    textBox.Text = textValue.Value
    while true do
        textValue.Value = "Free Time"
        textBox.Text = textValue.Value
        wait(1)
        textValue.Value = "Testing Time"
        textBox.Text = textValue.Value
        wait(1)
        textValue.Value = "Riot Time"
        textBox.Text = textValue.Value
        if player.Team.Name == "Team 1" then
            toolGive.Parent = player:WaitForChild("Backpack")
        end
        wait(1)
    end
end)

Tell me if there are still more issues, and hope it helps you!

0
Still doesn't work darieus887 -3 — 5y
0
Still doesn't work. I also changed from StarterGui to PlayerGui, but it still doesn't work.. darieus887 -3 — 5y
0
Nevermind. I managed to fix it. darieus887 -3 — 5y
0
Good Time_URSS 146 — 5y
Ad

Answer this question