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

Models won't clone from lighting?

So, In a test game I'm making, you spawn in a room. You touch a button, and it picks a room randomly from lighting, clones it in, teleports you to the room, and deletes the last room you were in. There's another button in the new room, which does the same thing as the last room (so its basically an endless assortment of rooms). This works fine in test mode, however in an actual server, it fails to work. When i hit the button, it teleports me to the middle of the baseplate, and no room spawns in. A singular script is incharge of the random room picking. This is the script:

t = script.Parent

t.Changed:connect(function()
	print("Changing Room...")
	local r = math.random(1,3)
	if r == 1 then
		game.Lighting.defroom1:Clone().Parent = workspace
		game.Workspace.Player.Torso.CFrame = CFrame.new(game.Workspace.defroom1.spawn.Position)
		elseif r == 2 then
		game.Lighting.defroom2:Clone().Parent = workspace
		game.Workspace.Player.Torso.CFrame = CFrame.new(game.Workspace.defroom2.spawn.Position)
		elseif r == 3 then
		game.Lighting.defroom3:Clone().Parent = workspace
		game.Workspace.Player.Torso.CFrame = CFrame.new(game.Workspace.defroom3.spawn.Position)
	end
end)

(NOTE: The script is located in Workspace > ValueHold (A folder I made) > RoomCount (A number Value) > This script)

1 comment

0

I don't see an error in your script. Does the output show anything? Also, instead of keeping models in Lighting, use ServerStorage

1 answer

✓ Accepted answer

You can possibly try this, not sure if it'll work due to the fact I don't have anything to test it with.

t = script.Parent
defroom1 = game.Lighting.defroom1
defroom2 = game.Lighting.defroom2
defroom3 = game.Lighting.defroom3

t.Changed:connect(function()
    print("Changing Room...")
    local r = math.random(1,3)
    if r == 1 then
        game.Lighting.defroom1:Clone()
        defroom1.Parent = game.Workspace
        game.Workspace.Player.Torso.CFrame = CFrame.new(game.Workspace.defroom1.spawn.Position)
        elseif r == 2 then
        game.Lighting.defroom2:Clone()
        defroom2.Parent = game.Workspace
        game.Workspace.Player.Torso.CFrame = CFrame.new(game.Workspace.defroom2.spawn.Position)
        elseif r == 3 then
        game.Lighting.defroom3:Clone()
        defroom3.Parent = game.Workspace    
        game.Workspace.Player.Torso.CFrame = CFrame.new(game.Workspace.defroom3.spawn.Position)
    end
end)

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