[FIXED]I have a problem when cloning a map with ServerStorage

Has been fixed by someone in a roblox dev discord server
Hi i’ve been trying to fix this bug on my game for the past 10 days and i’ve only found out what was the problem right now, basically, for my game, a map from ServerStorage is cloned, then placed on workspace on a specific posistion. Inside this map there’s a door code system, and the code answer is stored as an IntValue inside the display that displays the code when clicked.

The problem is, when it’s a cloned map, with this code,:

local remote = game.ReplicatedStorage.RemoteEvents.EnableKeycode
local TweenService = game:GetService("TweenService")
local door = script.Parent.Parent
local doorCharniere = door.PrimaryPart
local doorTweenInfo = TweenInfo.new()
local doorCharTween = TweenService:Create(doorCharniere, doorTweenInfo, {
	CFrame = doorCharniere.CFrame * CFrame.Angles(0, math.rad(120), 0)
})

remote.OnServerEvent:Connect(function(player,text)
	local CodeValue = door.Parent.Parent.PC.Screen.Code
	local GUI = player.PlayerGui.KeycodeGUI
	local fix = GUI.Frame.Frame.CodeSee
	if tonumber(text) == CodeValue.Value then
			script.Parent.Correct:Play()
			fix.Text = "Correct code"
		    fix.TextColor3 = Color3.fromRGB(0, 200, 0)
		    wait(1)
			fix.Text = ""
			fix.TextColor3 = Color3.fromRGB(255, 255, 255)
			script.Parent.DoorOpen:Play()
			doorCharTween:Play()
			script.Parent.Prompt.Enabled = false
		else
			script.Parent.Incorrect:Play()
			fix.Text = "Incorrect Code"
			fix.TextColor3 = Color3.fromRGB(200, 0, 0)
			wait(1)
			fix.Text = ""
			fix.TextColor3 = Color3.fromRGB(255, 255, 255)
	end
end)

it will always say that the answer is false even though it is correct .

But when it’s not a cloned map (copy paste on workspace), and I do the same thing, this time the script works normally (displays “Correct code” when code is correct and “Incorrect code” when it’s incorrect.

I don’t understand why this happens but i’m almost sure that it’s not my scripts problem.
Any help is appreciated!

Version that doesn’t have problems(copy paste of the game but without cloning script and other things): debug.rbxl (126.8 KB)

Version that has problems : Atmos [Indev] - Roblox

Main game script ( clones the map) :

local Players = game:GetService("Players")
local intermisionLegnth = 30
local choosingMapLength = 15
local InRound = game.ReplicatedStorage.InGame
local LobbySpawn = game.Workspace.Lobby.LobbySpawn
local Status = game.ReplicatedStorage.Status
local ChoosingMap = game.ReplicatedStorage.ChoosingMap
local RoundSpawn = game.Workspace.Lobby.LobbySpawn
local minutes = 5
local seconds = 0
local mapChosen = game.ServerStorage["_Colorful Warehouse"]

while true do
		for i = intermisionLegnth, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission ("..i..")"
		end
		ChoosingMap.Value = true
		for i = choosingMapLength, 0, -1 do
			wait(1)
			Status.Value = "Choosing map... ("..i..")"
		end
		InRound.Value = true
		ChoosingMap.Value = false
		local pos = {Vector3.new(0,0,0),Vector3.new(0,0,200),Vector3.new(0,0,400),Vector3.new(0,0,600),Vector3.new(0,0,800),Vector3.new(0,0,1000),Vector3.new(0,0,1200),Vector3.new(0,0,1400),Vector3.new(0,0,1600),Vector3.new(0,0,1800),Vector3.new(0,0,2000),Vector3.new(0,0,2200),Vector3.new(0,0,2400),Vector3.new(0,0,2600),Vector3.new(0,0,2800),Vector3.new(0,0,3000),Vector3.new(0,0,3200),Vector3.new(0,0,3400),Vector3.new(0,0,3600),Vector3.new(0,0,3800)}
		for i, player in pairs(Players:GetPlayers())do
			local clone = mapChosen:Clone()	
			clone.Parent = game.Workspace.CurrentlyLoaded
			clone:MoveTo(pos[i])
	    	print("Initiated map"..mapChosen.Name..i)
		local char = player.Character
			char.HumanoidRootPart.CFrame = clone.Spawn.CFrame
	     end
		repeat
		if seconds <= 0 then
			minutes = minutes - 1
			seconds = 59
		else
			seconds = seconds - 1
		end
		if seconds <= 9  then
			Status.Value = tostring(minutes)..":0"..tostring(seconds)
		else
			Status.Value = tostring(minutes)..":"..tostring(seconds)
			end
			wait(1)
		until minutes <= 0 and seconds <= 0
		minutes = 5
	    seconds = 0
	workspace.CurrentlyLoaded:ClearAllChildren()
	for i, player in pairs(Players:GetPlayers()) do
		local char = player.Character
		char.Humanoid.BreakJointsOnDeath = false
		char.Humanoid.Health = 0
	end	
	for i, player in pairs(Players:GetPlayers()) do
		local char = player.Character
		char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
	end
end

Also I noticed that the door tweening is also buggy when it’s a cloned map

2 Likes

should be:

local CodeValue = door.Parent.Parent.PC.Screen.Code.Value

Unsure though, show the hierachy of the models if you can.

1 Like

Nevermind, I just fully read your script and you used CodeValue.Value, my bad.

1 Like

The hierarchy of the models is here

Version that doesn’t have problems(copy paste of the game but without cloning script and other things): debug.rbxl (126.8 KB)

You can just screenshot the model and it’s children in workspace, you know.

1 Like

ok but it’s kinda long

here

Does anyone have an idea ? Maybe it’s too hard to solve oof

Are you using a local script. If yes then use a server script. If that doesn’t work, then put the map in ReplicatedStorage | Roblox Creator Documentation.

1 Like

Thanks for the advide, but is there another way ? I wanna make sure that people can’t steal my assets by putting the assets in the server side only, but if it works i’ll make sure to mark it as solution!

No, I don’t think there’s another way unfortunately.

1 Like

ok i’ll try it right now then thanks

I tried but sadly it still has the same problem that is so strange :frowning:
i’m 99% sure that it’s not the scripts fault because it works normally when I copy paste it via studio

Don’t use a local script. Use a server script.

1 Like

It’s all server scripts in the map, I think it might be something else

is there a script that changes the codeValue ?

1 Like

No there’s only a script that generates the code and sets the value as the code as soon as the cloned map is generated in workspace

try instead of “CodeValue = door.Parent.Parent.PC.Screen.Code” just type “CodeValue = 100”, this will give us a better idea of what the problem is

1 Like

Yea but door.Parent.Parent.PC.Screen.Code is a random ganerated integer between 1000 and 9999.
I don’t think there’s a problem with the script since it works perfectly when I just put it in workspace by hand

i’mma try to set it at a specific integer just to be sure

can you send me the script that generates the random code ?

You forgot to clone it. Do local mapChosen = game.ServerStorage["_Colorful Warehouse"]
:Clone()