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

Choosing a map from a local script?

Asked by 5 years ago
Edited 5 years ago

So I am making a murder game and I was trying to make it so it says the chosen game and spawns it in. I am doing this through a** LOCAL SCRIPT** because I am FireAllClients form the Script. Also the error is "Players.Nosh4309.PlayerGui.LocalScript:21: attempt to concatenate local 'gameChosen' (a userdata value)" What does this mean? I cant change it form not being local (Also the problem is** line 17 to 21**)

local client = game:GetService("Players").LocalPlayer
local RepStore = game:GetService("ReplicatedStorage")
local remote = RepStore.remote -- LOCATING THE REMOTE
local repstore = game.ReplicatedStorage
--
local Maps = repstore.Maps:GetChildren()
local School = repstore.Maps.School
local Beach = repstore.Maps.Beach

remote.OnClientEvent:Connect(function()
    local pgui1 = client.PlayerGui
    pgui1:WaitForChild("ScreenGui").TextLabel.Text = "Starting game!" 
wait(3)
    local pgui = client.PlayerGui
    pgui:WaitForChild("ScreenGui").TextLabel.Text = "Choosing a map"
    wait(3)
    local RanGame = math.random(1,#Maps)
    local gameChosen = Maps[RanGame] --Problem is here

    local pgui = client.PlayerGui
    pgui:WaitForChild("ScreenGui").TextLabel.Text = "Map chosen ".. gameChosen --end
    wait(1)
    local gameChosenClone = gameChosen:Clone()

    if gameChosenClone.Name == "Beach" then
    Beach:Clone().Parent = game.Workspace.MapSelected
    elseif gameChosenClone.Name == "School" then
    School:Clone().Parent = game.Workspace.MapSelected

    end
end)

0
The reason is because you attempted to concatenate the map itself. Add a .Name. And you should clone maps on the server, that way they replicate. If that's not your desire then you can disregard what I said. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You should cloning/moving/adding parts or groups in a server script instead of a client script. Also, you are cloning the maps two times.

Look:

local gameChosenClone = gameChosen:Clone() -- Here you clone the map chosen in the Maps[RanGame]
if gameChosenClone.Name == "Beach" then
    Beach:Clone().Parent = game.Workspace.MapSelected -- Here you clone the map again if the map chosen in the Maps[RanGame] is named "Beach"
elseif gameChosenClone.Name == "School" then
    School:Clone().Parent = game.Workspace.MapSelected -- Here you clone the map again if the map chosen in the Maps[RanGame] is named "School"
end

Last thing, you forgot to get the name of the chosen map. Example:

local text = "Map Chosen: " .. gameChosen -- This is wrong, you miss the ".Name"
local text = "Map Chosen: " .. gameChosen.Name -- This is right, you are reading the chosen map's name

I hope it helped.

Ad

Answer this question