More Than One Player Breaks My Game

Hello, I am creating a game but I just ran into a problem where if there is two people in game, there are problems. For example, lets use a click for point example. One of the player clicks on the button, but the other player gets the points. Why is this? I could show script if needed, any help is appreciated.

Show the script please so we actually know how to fix it.

Touch Block for Point Script

local V_ = game:GetService("ServerScriptService")
local PopIt = script.Parent
local db = false
local B_ = game.ServerScriptService.Statistics
local M_ = require(B_.GameStats)
local PointsForPop = M_.Pops
local Cooldown = M_.CooldownForSmall

game.Players.PlayerAdded:Connect(function(Player)
	local function Pop(hit)
		local human = hit.Parent:FindFirstChildWhichIsA("Humanoid")
		if human and db == false then
			local player = game.Players:FindFirstChild(hit.Parent.Name)
			db = true
			PopIt.Transparency = 1
			PopIt.CanCollide = false

			Player.leaderstats.Pops.Value = Player.leaderstats.Pops.Value + 1			
		end
	end
	
	script.Parent.Touched:Connect(Pop)
	while wait() do
		wait(Cooldown)
		db = false
		PopIt.Transparency = 0
		PopIt.CanCollide = true
		
	end
end)

Check if Tutorial Is Done

game.ReplicatedStorage.remoteTutorials.checkTutorial.OnServerEvent:Connect(function(Player)
	
	local function notTutorial()
		
		local playerGui = Player:WaitForChild("PlayerGui")
		local TutorialUI = script.tutorialGuide:Clone()
		TutorialUI.Parent = playerGui
		
	end
	
	local function doneTutorial()	
		
		local character = Player.Character
		local LowerTorso = character:WaitForChild("HumanoidRootPart")
		if Player.MapWorld.Value ~= 0 then

			local MapArea = game.Workspace.Maps:FindFirstChild(Player.MapWorld.Value)
			local Character = Player.Character
			Character:MoveTo(MapArea.Position)


		end
	end
		
	
	if Player.tutorialStats.didTutorial.Value == "false" then	
		
		notTutorial()		
	else	
		doneTutorial()
		
	end 	
end)

Tutorial Is Done:

game.ReplicatedStorage:WaitForChild("remoteTutorials").finishedTutorial.OnServerEvent:Connect(function(Player, stat)
	
	wait(2)
stat.Changed:Connect(function()
	
	local newMap = script.LoadNewMap
		local finishedGui = script.TutorialGuis
		local confetti = script.ConfettiCannon
	
	local PlayerGui = Player:WaitForChild("PlayerGui")
		
		finishedGui.Parent = PlayerGui	
		finishedGui:Clone()
		confetti.Parent = PlayerGui
		confetti:Clone()
		
		
		wait(6)
		
		newMap.Parent = PlayerGui
		newMap:Clone()

		
end)
end)

If you want to see the problem, I can send you the game link.

Switch this script to:

--//Services
local Players = game:GetService("Players")

--//Variables
local Part = script.Parent

--//Controls
local debounce = false
local cooldownTime = 1

--//Functions
Part.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	
	if Player and not debounce then
		debounce = true
		
		Part.Transparency = 1
		Part.CanCollide = false
		
		Player.leaderstats.Pops.Value += 1
		
		task.wait(cooldownTime)
		debounce = false
	end
end)

Alright, that fixed part of it. Now the problem is that only one of the person gets the finished tutorial UI.
Here is the script,

game.ReplicatedStorage:WaitForChild("remoteTutorials").finishedTutorial.OnServerEvent:Connect(function(Player, stat)

	wait(2)
stat.Changed:Connect(function()
	
		local newMap = script:FindFirstChild("LoadNewMap")
		local finishedGui = script:FindFirstChild("TutorialGuis")
		local confetti = script:FindFirstChild("ConfettiCannon")
	
	local PlayerGui = Player:WaitForChild("PlayerGui")
		
		finishedGui.Parent = PlayerGui	
		finishedGui:Clone()
		confetti.Parent = PlayerGui
		confetti:Clone()
		
		
		wait(6)
		
		newMap.Parent = PlayerGui
		newMap:Clone()

		
end)
end)
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local RemoteEvent = ReplicatedStorage.remoteTutorials.finishedTutorial.OnServerEvent

--//Functions
RemoteEvent.OnServerEvent:Connect(function(player, stat)
	local PlayerGui = player:WaitForChild("PlayerGui")
	task.wait(2)
	
	stat:GetPropertyChangedSignal("Value"):Connect(function()
		local finishedGui = script:WaitForChild("TutorialGuis"):Clone()
		finishedGui.Parent = PlayerGui
		
		local confetti = script:WaitForChild("ConfettiCannon"):Clone()
		confetti.Parent = PlayerGui

		task.wait(6)
		
		local newMap = script:WaitForChild("LoadMap"):Clone()
		newMap.Parent = PlayerGui
	end)
end)
1 Like

It only worked for one of the players, here is the error message I got.

Error was on this line.

local finishedGui = script.TutorialGuis

Try my edited script.

30

1 Like

it should be

local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local RemoteEvent = ReplicatedStorage.remoteTutorials.finishedTutorial.OnServerEvent

--//Functions
RemoteEvent.OnServerEvent:Connect(function(player, stat)
	local PlayerGui = player:WaitForChild("PlayerGui")
	task.wait(2)
	
	stat:GetPropertyChangedSignal("Value"):Connect(function()
		local finishedGui = script:WaitForChild("TutorialGuis"):Clone()
		finishedGui.Parent = PlayerGui
		
		local confetti = script:WaitForChild("ConfettiCannon"):Clone()
		confetti.Parent = PlayerGui

		task.wait(6)
		
		local newMap = script:WaitForChild("LoadMap"):Clone()
		newMap.Parent = PlayerGui
	end)
end)

cloning an instance will set its parent automatically to nil so try this please

Your script does the exact same thing.

Which is why you set the parent after, (which is what I already did).

no it does not you called clone but it would clone it into nil so it wouldnt actually clone

when you cloned said gui you did not set it as a variable therefore you couldnt access it
and as you know you cant access instances parented to nil without saving it to memory aka a variable

I’m cloning the referenced UI and parenting it after. You are also doing the exact same thing in your script, try it out in studio as I tried yours out too and it works the exact same.

try it twice and you’ll see the problem

Ohhh now I see it, sorry for the misunderstanding.