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);
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