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

Concatenate team name with string?

Asked by 4 years ago

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);
0
Why do you have the semicolons? Spjureeedd 385 — 4y
0
i am transitioning from c++, so its a habit Claverbot 4 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question