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

Why is my text for my capture point not working when I put variables into the message?

I took some random free model capture point off the toolbox, and attempted to modify it to become a capture point that updates a GUI at the top of the screen that keeps track of how long each team has held it. However, I keep getting some errors and the GUI won't update with the variables. I'm almost certain I'm doing something really stupid, but I've tried to fix this many many times, and it just refuses to work with variables. How do I fix this?

(The code that gets an error is the line below this sentence, and the script is in the screengui as a localscript)

script.Parent.TextLabel.Text = "Team holding: BLU BLU:" tostring(blu) " RED:" tostring(red)

(all code if needed)

team = game.Workspace["Capture point"].Part

pole = game.Workspace["Capture point"].Pole

local teamholding = "None"

local red = 0

local blu = 0

function onTouch(hit)

local user = game.Players:GetPlayerFromCharacter(hit.Parent)

if user ~= nil then

team.BrickColor = user.TeamColor

pole.Handles.Color = user.TeamColor

print(user.TeamColor)

  

if user.TeamColor.Name == "Navy blue" then

teamholding = "BLU"

script.Parent.TextLabel.Text = "Team holding: BLU BLU:" tostring(blu) " RED:" tostring(red)

  

end

  

while teamholding == "BLU" do

blu = blu + 1

script.Parent.TextLabel.Text = "Team holding: BLU BLU:" tostring(blu) " RED:" tostring(red)

wait(1)

end

  

if user.TeamColor.Name == "Really red" then

teamholding = "RED"

script.Parent.TextLabel.Text = "Team holding: BLU BLU:" + tostring(blu) +" RED:" + tostring(red)

while teamholding == "RED" do

red = red + 1

script.Parent.TextLabel.Text = "Team holding: BLU BLU:" + tostring(blu) +" RED:" + tostring(red)

wait(1)

end

  

end

end

end

  

team.Touched:connect(onTouch)

1 answer

✓ Accepted answer

The problem is simple: You have no concatenation symbols.

Concatenation is the act of inserting a string or number into another string. Lua's symbol for concatenation is two periods ... Here is an example of concatenation:

script.Parent.TextLabel.Text = "Team holding: BLU BLU: " .. tostring(blu) .. " RED: " .. tostring(red)

The above line should make the following string:

"Team holding: BLU BLU: (blu) RED: (red)"

Concatenation is simple and rather easy, and it will become very useful to you.

1 comment

0

"(blu)" is the first tostring and "(red)" is the second

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