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

Concatenate team name with string?

I have a script that when fires it takes the local players team and attempts to concatenate it to a string. I say attempts because when i actually test it it returns nil value. How can i avoid this?

Server script:



local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
local remoteEvent = ReplicatedStorage:WaitForChild("Mobilization")
    
    local function onCreatePart(player)
    local cities = workspace:FindFirstMatching({
		Name = player .. "_cities"; --doesnt work
		IsA = "Model";
	})
	print(cities.Name);
    end
	
     
remoteEvent.OnServerEvent:Connect(onCreatePart)

Localscript on gui button click:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local player = game.Players.LocalPlayer.Team; --It should concatenate with this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Mobilization")
     

script.Parent.MouseButton1Click:Connect(remoteEvent:FireServer(player))
print(player);

2 comments

0

Why do you have the semicolons?

0

i am transitioning from c++, so its a habit

1 answer

i fixed it:

local:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local string player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Mobilization")
     
    -- Fire the remote event
script.Parent.MouseButton1Click:Connect(function()
	ReplicatedStorage.Mobilization:FireServer(player)
	end)

server:

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Teams = game:GetService("Teams")
    local remoteEvent = ReplicatedStorage:WaitForChild("Mobilization")
	local model = game.ReplicatedStorage.guy
    
    -- Create a new part
    local function Mobilization(player)
	local player = player.Team.Name
	local strcity = player .. "_cities"
	local strunit = player .. "_units"
	local city = workspace.cities
	print(strcity, strunit)
	for i = 1, 3 do
		local n = i
		tostring(n)
		local clone = model:Clone()
		local spawnlocation = city[strcity][n].Position
		clone.Parent = game.Workspace.units[strunit]
		clone:MoveTo(spawnlocation)			
	end
	
	
    end
	
     
    remoteEvent.OnServerEvent:Connect(Mobilization)

also heres an entire code to spawning multiple units from 3 cities for an rts

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