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

Why does this script only clone the model when I try it in Studio and not in game?

The script below should clone a model from serverstorage into workspace, this way I could reduce lag because unnecessary parts will be in serverstorage. It should clone it when I touch a certain part that is in workspace. (CanCollide = false) This works in Studio but when I try it in game nothing happens when I walk through the part.

Script:

x = 0
game.Workspace.TerrainButton1.Touched:connect(function(part) -- This clones the Terrain
	local parent = part.Parent
	if game.Players:GetPlayerFromCharacter(parent) then
		if x ~= 1 then
			local terrain1 = game.ServerStorage.Terrain1
			terrain1:clone().Parent = game.Workspace
			x = 1
		end
	end
end)


game.Workspace.HordeButton1.Touched:connect(function(part) -- This clones the Zombies
	local parent = part.Parent
	if game.Players:GetPlayerFromCharacter(parent) then
		if x ~= 2 then
			local horde1 = game.ServerStorage.Horde1
			horde1:clone().Parent = game.Workspace
			x = 2
		end
	end
end)


game.Workspace.RemoveButton1.Touched:connect(function(part) -- This deletes both the terrain and the zombies
	local parent = part.Parent
	if game.Players:GetPlayerFromCharacter(parent) then
		x = 2
		local horde1 = game.Workspace.Horde1
		local terrain1 = game.Workspace.Terrain1
		if horde1 ~=nil then
			horde1:destroy()
		end
		if terrain1 ~= nil then
			terrain1:destroy()
		end
	end
end)

1 answer

✓ Accepted answer

easy mistakes, when defining variables make sure you do WaitForChild("Name") at the end For example

local terrain1 = game.ServerStorage:WaitForChild("Terrain1")

This is a fix just change the rest

4 comments

0

Ok thx! Do I have to do this for the second line too? Or just for variables?

0

You can try with only variables if it still doesn't work then do it for the second line too, accept the answer if it works ;D

0

Finally had the time to test it and it works, so thanks a lot again! :D

0

No Problem! Thanks for accepting my answer :D

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