Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

--// 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.

2 comments

0

Is it because I'm using a loop inside a function?

0

You're using StarterGui instead of PlayerGui. Modifying StarterGui will only change the gui for players who come after you change it.

1 answer

✓ Accepted answer

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!

4 comments

0

Still doesn't work

0

Still doesn't work. I also changed from StarterGui to PlayerGui, but it still doesn't work..

0

Nevermind. I managed to fix it.

0

Good

This discussion is preserved as it was. New answers, comments, and votes are closed.