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

Why doesn't this work?

I'm attempting to make a terminal for war groups. Yet i'm a new scripter. Why isn't this working?

bin = script.Parent

if game.Players.GetChildren.Color "Bright red" then
	function onTouched(part)
	game.Workspace.Terminal.Colors.Part1.BrickColor = BrickColor.new("Medium stone grey") --Change This Color To Raider Team Color
	game.Workspace.Terminal.Colors.Part2.BrickColor = BrickColor.new("Medium stone grey") --Change This Color To Raider Team Color
	game.Workspace.Terminal.Colors.Part3.BrickColor = BrickColor.new("Medium stone grey") --Change This Color To Raider Team Color
	wait(7)
	local hint = Instance.new('Hint', workspace)
	hint.Text = "Raiders have capture the base! 20 Minutes till raiders win!"
	wait(5)
	game.Workspace.Message:Remove()
	wait(60)
	local hint = Instance.new('Hint', workspace)
	hint.Text = "5%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "10%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "15%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "20%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "25%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "30%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "35%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "40%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "45%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "50%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "55%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "60%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "65%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "70%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "75%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "80%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "85%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "90%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "95%"
	wait(60)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "100%"
	wait(1)
	game.Workspace.Message:Remove()
	local hint = Instance.new('Hint', workspace)
	hint.text = "The Raiders have won! Good Game."
	wait(3)
	game.Workspace.Hint:Remove()
	end
	bin.Touched:connect(onTouched)

if game.Players.GetPlayers.TeamColor "Medium stone grey" then
	function onTouched(part)
	wait (5)
	game.Workspace.Terminal.Colors.Part1.BrickColor = BrickColor.new("Really red") --Change This Color To Your Group Color
	game.Workspace.Terminal.Colors.Part2.BrickColor = BrickColor.new("Really red") --Change This Color To Your Group Color
	game.Workspace.Terminal.Colors.Part3.BrickColor = BrickColor.new("Really red") --Change This Color To Your Group Color
	game.Workspace.Message:Remove()
	game.Workspace.Terminal.Part.Raiders.Disabled = true
	local hint = Instance.new('Hint', workspace)
	hint.text = "(Group Name) has taken back the base!" --Insert Group Name Where it Says (Group Name). Remove the parenthesis. 
	wait(5)
	game.Workspace.Message:Remove()
	bin.Touched:connect(onTouched)
end

1 comment

1

This has a ton of errors.

1 answer

First: no reason to create and destroy hints. Just use the same one.

(As a matter of fact, you should say hint:Destroy() rather than refer to it as game.Workspace.Message since it isn't clear where that's coming from).

Blam. 42 useless lines removed.

Now tab your code correctly and you'll see the ends don't match the blocks that have started.

In general, having connections that are in ifs is usually wrong. In this case, having an if doesn't make any sense around the onTouched event. The condition is also completely meaningless and wrong.


There's still a ton of repetition. Use a loop:

for progress = 5, 100, 5 do
	wait(60)
	hint.Text = progress .. "%"
end

Blam. 35 unnecessary lines removed.


We're left with two functions that do something based on, I'm guessing, which team touched the part.

We should have one function for this, not two.

function onTouched(part)
	local character = part.Parent
	local player = game.Players:GetPlayerFromCharacter( character )
	if character and player then
		local team = player.TeamColor
		if team == BrickColor.new("Medium stone grey") then
			-- do whatever you want when
			-- a Grey person touches this
		elseif team == BrickColor.new("Really red") then
			-- do whatever you want when
			-- a Red person touches this
		end
	end
end

bin.Touched:connect(onTouched)

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