So I have this script here that when I talk to an NPC it runs. Although it works in Studio but does not work in game of Play Mode in Studio. And for some reason there are no errors in any logs. How can I fix this?

Here is the script

script.Parent.Dialog.DialogChoiceSelected:connect(function(player,choice)
	print(choice.Name)
	print(player.Name)
	if choice.Name == "Shack" then
	local HomeStats = player.HomeStats
	local PlotN = player.HomeStats.PlotN	
	
	if PlotN.Value == 0 then
	print(HomeStats.PlotN.Value)
		choice.ResponseDialog = "You must claim a plot before you can load your home"
		player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must claim a plot before you can load your home"
		wait(5)
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		choice.ResponseDialog = "Home Loaded."
	else
	if HomeStats.HasHome.Value == true then
	if HomeStats.HomeType.Value == "Shack" then
		if game.Workspace:FindFirstChild("Shack_"..player.Name) == nil and game.Workspace:FindFirstChild("Surburban_"..player.Name) == nil and game.Workspace:FindFirstChild("Modern_"..player.Name) == nil then
		local Home = game.Lighting["Home-Shack"]:Clone()
		Home.Parent = game.Workspace
		game.Workspace["Home-Shack"]:MoveTo(game.Workspace["Plot_"..PlotN.Value].Plot.Position)
		game.Workspace["Home-Shack"].Owner.Value = player.Name
		----------------------------------------------
		--local H = player.HomeStats
	
	--if H.Part.Value == true then
		
		--game.Workspace["Home-Shack"].Upgrades.Part.CanCollide = true
		--game.Workspace["Home-Shack"].Upgrades.Part.Transparency = 0
		
	--elseif H.Porch.Value == true then
		
		--game.Workspace["Home-Shack"].Upgrades.Porch.CanCollide = true
		--game.Workspace["Home-Shack"].Upgrades.Porch.Transparency = 0		
		
	--end
	----------------------------------------------------------------
		game.Workspace["Home-Shack"].Name = "Shack_"..player.Name
		--Rotation
		local function TransformModel(model, newCFrame)
   		model:SetPrimaryPartCFrame(newCFrame)
		end 
		print(game.Workspace["Plot_"..PlotN.Value].Rotation.Rotation.Y)
		local model = game.Workspace["Shack_"..player.Name] 
		local rotatedCFrame = model:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(game.Workspace["Plot_"..PlotN.Value].Rotation.Rotation.Y), 0)

		TransformModel(model, rotatedCFrame)
		--Rotation
		else
			choice.ResponseDialog = "You already have a home loaded on a plot."
			player.PlayerGui.NotifGui.FrameB.Notification.Text = "You already have a home loaded on a plot"
			wait(5)
			player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
			choice.ResponseDialog = "Home Loaded."
		end
		end
	else
		choice.ResponseDialog = "You must buy a home in order to load your home."
		player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must buy a home in order to load your home"
		wait(5)
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
	end
	end
	end
	
if choice.Name == "Surburban" then
	local HomeStats = player.HomeStats
	local PlotN = player.HomeStats.PlotN	
	
	if PlotN.Value == 0 then
	print(HomeStats.PlotN.Value)
		choice.ResponseDialog = "You must claim a plot before you can load your home"
		player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must claim a plot before you can load your home"
		wait(5)
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		choice.ResponseDialog = "Home Loaded."	
	else
	if HomeStats.HasHome.Value == true then
	if HomeStats.HomeType1.Value == "Suburban" then
		if game.Workspace:FindFirstChild("Suburban_"..player.Name) == nil and game.Workspace:FindFirstChild("Shack_"..player.Name) == nil and game.Workspace:FindFirstChild("Modern_"..player.Name) == nil then
		local Home = game.Lighting["Home-Suburban"]:Clone()
		Home.Parent = game.Workspace
		game.Workspace["Home-Suburban"]:MoveTo(game.Workspace["Plot_"..PlotN.Value].Plot.Position)
		game.Workspace["Home-Suburban"].Owner.Value = player.Name
		----------------------------------------------
		--local H = player.HomeStats
	
	--if H.Part.Value == true then
		
		--game.Workspace["Home-Shack"].Upgrades.Part.CanCollide = true
		--game.Workspace["Home-Shack"].Upgrades.Part.Transparency = 0
		
	--elseif H.Porch.Value == true then
		
		--game.Workspace["Home-Shack"].Upgrades.Porch.CanCollide = true
		--game.Workspace["Home-Shack"].Upgrades.Porch.Transparency = 0		
		
	--end
	----------------------------------------------------------------
		game.Workspace["Home-Suburban"].Name = "Suburban_"..player.Name
		--Rotation
		local function TransformModel(model, newCFrame)
   		model:SetPrimaryPartCFrame(newCFrame)
		end 
		print(game.Workspace["Plot_"..PlotN.Value].Rotation.Rotation.Y)
		local model = game.Workspace["Suburban_"..player.Name] 
		local rotatedCFrame = model:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(game.Workspace["Plot_"..PlotN.Value].Rotation.Rotation.Y), 0)

		TransformModel(model, rotatedCFrame)
		--Rotation
		--game.Workspace["Plot_"..PlotN.Value].Grass.BrickColor = BrickColor.new("Camo")
		else
			choice.ResponseDialog = "You already have a home loaded on a plot."
			player.PlayerGui.NotifGui.FrameB.Notification.Text = "You already have a home loaded on a plot"
			wait(5)
			player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
			choice.ResponseDialog = "Home Loaded."
		end
		end
	else
		choice.ResponseDialog = "You must buy a home in order to load your home."
		player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must buy a home in order to load your home"
		wait(5)
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		choice.ResponseDialog = "Home Loaded."
	end
	end
	end

if choice.Name == "Modern" then
	local HomeStats = player.HomeStats
	local PlotN = player.HomeStats.PlotN	
	
	if PlotN.Value == 0 then
	print(HomeStats.PlotN.Value)
		choice.ResponseDialog = "You must claim a plot before you can load your home"
		player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must claim a plot before you can load your home"
		wait(5)
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		choice.ResponseDialog = "Home Loaded."	
	else
	if HomeStats.HasHome.Value == true then
	if HomeStats.HomeType2.Value == "Modern" then
		if game.Workspace:FindFirstChild("Modern_"..player.Name) == nil and game.Workspace:FindFirstChild("Shack_"..player.Name) == nil and game.Workspace:FindFirstChild("Suburban_"..player.Name) == nil then
		local Home = game.Lighting["Home-Modern"]:Clone()
		Home.Parent = game.Workspace
		game.Workspace["Home-Modern"]:MoveTo(game.Workspace["Plot_"..PlotN.Value].Plot.Position)
		game.Workspace["Home-Modern"].Owner.Value = player.Name
		----------------------------------------------
		--local H = player.HomeStats
	
	--if H.Part.Value == true then
		
		--game.Workspace["Home-Shack"].Upgrades.Part.CanCollide = true
		--game.Workspace["Home-Shack"].Upgrades.Part.Transparency = 0
		
	--elseif H.Porch.Value == true then
		
		--game.Workspace["Home-Shack"].Upgrades.Porch.CanCollide = true
		--game.Workspace["Home-Shack"].Upgrades.Porch.Transparency = 0		
		
	--end
	----------------------------------------------------------------
		game.Workspace["Home-Modern"].Name = "Modern_"..player.Name
		--Rotation
		local function TransformModel(model, newCFrame)
   		model:SetPrimaryPartCFrame(newCFrame)
		end 
		print(game.Workspace["Plot_"..PlotN.Value].Rotation.Rotation.Y)
		local model = game.Workspace["Modern_"..player.Name] 
		local rotatedCFrame = model:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(game.Workspace["Plot_"..PlotN.Value].Rotation.Rotation.Y), 0)

		TransformModel(model, rotatedCFrame)
		--Rotation
		--game.Workspace["Plot_"..PlotN.Value].Grass.BrickColor = BrickColor.new("Camo")
		else
			choice.ResponseDialog = "You already have a home loaded on a plot."
			player.PlayerGui.NotifGui.FrameB.Notification.Text = "You already have a home loaded on a plot"
			wait(5)
			player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
			choice.ResponseDialog = "Home Loaded."
		end
		end
	else
		choice.ResponseDialog = "You must buy a home in order to load your home."
		player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must buy a home in order to load your home"
		wait(5)
		player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		choice.ResponseDialog = "Home Loaded."
	end
	end
	end

	if choice.Name == "UnPlot" then
	local PlotN = player.HomeStats.PlotN
		if PlotN.Value ~= 0 then
			local Parts = game.Workspace.PlotButtons:GetChildren()
			for i, v in pairs(Parts) do
				if v.Owner.Value == player.Name then
					v.BrickColor = BrickColor.new("Parsley green")
					v.ClickDetector.MaxActivationDistance = 32
					v.Owner.Value = ""
					if game.Workspace:FindFirstChild("Shack_"..player.Name) ~= nil then
						game.Workspace["Shack_"..player.Name]:remove()
						--game.Workspace["Plot_"..PlotN.Value].Grass.BrickColor = BrickColor.new("Brown")
						PlotN.Value = 0
					elseif game.Workspace:FindFirstChild("Suburban_"..player.Name) ~= nil then
						game.Workspace["Suburban_"..player.Name]:remove()
						--game.Workspace["Plot_"..PlotN.Value].Grass.BrickColor = BrickColor.new("Brown")
						PlotN.Value = 0
					elseif game.Workspace:FindFirstChild("Modern_"..player.Name) ~= nil then
						game.Workspace["Modern_"..player.Name]:remove()
						--game.Workspace["Plot_"..PlotN.Value].Grass.BrickColor = BrickColor.new("Brown")
						PlotN.Value = 0
					end
				end
			end
			PlotN.Value = 0
		else
			player.PlayerGui.NotifGui.FrameB.Notification.Text = "You must have a plot in order to switch it"
			wait(5)
			player.PlayerGui.NotifGui.FrameB.Notification.Text = ""
		end
	end
end)

2 comments

0

Anyone have any ideas?

0

Try formatting your code with tab. See this answer for help on formatting (it makes code easier to read understand): https://scriptinghelpers.org/questions/33761/soldier-name-changer-loop-and-death-checking-system