[SOLVED] Why is only one local script receiving remote event but not the other

I would like to get both of two different local scripts (yes they are on starterGUI) to receive a remote event. For some reason, when the event is fired (and yes it does fire and is in replicated storage) only the first of the two local scripts receives it.
print1

I’ve looked at this post and tried it’s “solution” which was applying a wait before one of the script’s event but it just makes the other one fire.
print2

This doesn’t make sense, and I’m about to minorly crash out. Please help me :pleading_face::pleading_face:

4 Likes

it’s been a whole 7 minutes and no replys. I’m getting impatient :rage:.
not to mention, the previous “topic” that I posted immediately got a bunch of replys, what the follicle

5 Likes

There’s not much we can do to help without your code…

5 Likes

can you provide ANY other context? like code, snippets, explorer

(its like asking for help but not telling the person what the problem is)

3 Likes

oh right yeah yeah
so this is the code from server:

   event.Owned:FireClient(plr, saveData[plr.UserId].inventory)

and these are the codes from the two local scripts

local 1:

event.Owned.OnClientEvent:Connect(function(inventoryTabl)
	print("local 1 recieved")
	for i,id in ipairs(inventoryTabl) do
		itemTabl[id].owned = true
	end
	
	if itemTabl[option].owned then
		buyButton.BackgroundColor3 = Color3.new(0,0,0)
		buyButton.Text = "Owned"
	else
		buyButton.BackgroundColor3 = Color3.new(0, 255, 0)
		buyButton.Text = "Purchase?"
	end
end)

aaaaaannndd local 2:

event.Owned.OnClientEvent:Connect(function(InventoryDict)
	print("local 2 recieved")
	inventory:ClearAllChildren()
	for i, ID in ipairs(InventoryDict) do
		local itemType = idSystem.itemTabl[ID].itemType
		if itemType == "part" then
			local itemClone = parts:WaitForChild(idSystem.itemTabl[ID].name):Clone()
			itemClone.Parent = inventory
		end
		if itemType == "pack" then
			local itemClone = packs:WaitForChild(idSystem.itemTabl[ID].name):Clone()
			itemClone.Parent = inventory
		end
	end
end)
2 Likes

We’ll need to see the entirety of both scripts

1 Like

are you sure that the server gets the plr correctly?
are you sure that the second script isn’t disabled or yielded by another function? (via: wait, task.wait, waitforchild, etc.)

2 Likes

ok
server script:

local plrs = game:GetService("Players")
local server = game:GetService("ServerScriptService")
local rStore = game:GetService("ReplicatedStorage")
local sStore = game:GetService("ServerStorage")
local rServ = game:GetService("RunService")
local dataServ = game:GetService("DataStoreService")

local stuff = rStore:WaitForChild("Stuff")
local parts = stuff:WaitForChild("Parts")
local packs = stuff:WaitForChild("Packs")

local gameSave = dataServ:GetDataStore("gameSave")
local saveData = {}

local event = rStore:WaitForChild("Events")
local servEvent = server:WaitForChild("ServCommunication")

local inventories = sStore:WaitForChild("Inventories")
local scripts = sStore:WaitForChild("Scripts")

local idSystem = require(rStore:WaitForChild("IDSystem"))
local itemTabl = idSystem.itemTabl


local function save(plr)
	local sucess
	local errorMsg
	local attempts = 0
	local items = 0
	
	local inventory = inventories:WaitForChild(plr.Name)
	local packID = inventory:WaitForChild("packId").Value
	
	saveData[plr.UserId].inventory = {}
	saveData[plr.UserId].hotbar = {}
	saveData[plr.UserId].pack = packID
	
	for i,child in pairs(inventories:FindFirstChild(plr.Name):GetChildren()) do
		items += 1
		local id = child:FindFirstChild("ID")
		if id then
			table.insert(saveData[plr.UserId].inventory, id.Value)
		end
	end
	for i,child in pairs(inventories:FindFirstChild(plr.Name).hotbar:GetChildren()) do
		local id = child:FindFirstChild("ID")
		if id then
			table.insert(saveData[plr.UserId].hotbar, id.Value)
		end
	end
	saveData[plr.UserId].taps = plr.leaderstats.Thingies.Value
	saveData[plr.UserId].cash = plr.leaderstats.Wealth.Value
	repeat
		sucess, errorMsg = pcall(function()
			gameSave:SetAsync(plr.UserId, saveData[plr.UserId])
		end)
		
		attempts += 1
		if not sucess then
			warn("somethin went wrong with".. plr.Name.. "'s data")
			task.wait(3)
		end
		
	until sucess or attempts >=10
	if sucess then
		print(plr.Name.."'s data sucessfuly saved")
	else
		warn(plr.Name.."'s data couldn't save")
	end
	local complete = true
	return complete
end


plrs.PlayerAdded:Connect(function(plr)
	local charLoaded = false
	plr.CharacterAdded:Connect(function(char)
		charLoaded = true
		
		--Motor6Ds
		local toolAt = Instance.new("Motor6D")
		toolAt.Name = "ToolAttach"
		toolAt.Parent = char:WaitForChild("Right Arm")
		toolAt.Part0 = char:WaitForChild("Right Arm")
		
	end)
	repeat
		task.wait(0.05)
	until charLoaded
	
	--Leaderstats
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local taps = Instance.new("IntValue")
	taps.Name = "Thingies"
	taps.Parent = leaderstats
	
	local cash = Instance.new("IntValue")
	cash.Name = "Wealth"
	cash.Parent = leaderstats
	
	
	--inventories
	local inventory = Instance.new("Folder")
	inventory.Name = plr.Name
	inventory.Parent = inventories
	
	local hotbar = Instance.new("Folder")
	hotbar.Name = "hotbar"
	hotbar.Parent = inventory
	
	
	local packID = Instance.new("IntValue")
	packID.Name = "packId"
	packID.Parent = inventory
	
	
	--Player Save
	local sucess
	local plrData
	local attempts = 0
	
	repeat
		sucess, plrData = pcall(function()
			return gameSave:GetAsync(plr.UserId)
		end)
		
		attempts += 1
		
		if not sucess then
			warn("somethin went wrong with".. plr.Name.. "'s data")
			task.wait(3)
		end
		
		
	until sucess or attempts >= 10
	
	
	if sucess then
		if not plrData then
			print("assigned default data for".. plr.Name)
			saveData[plr.UserId] = {
				["taps"] = 0,
				["cash"] = 0,
				["rebirth"] = 0,
				["inventory"] = {1,20},
				["hotbar"] = {1,},
				["pack"] = 20,
			}
		else
			saveData[plr.UserId] = plrData
			saveData[plr.UserId].taps = saveData[plr.UserId].taps or 0
			saveData[plr.UserId].cash = saveData[plr.UserId].cash or 0
			saveData[plr.UserId].rebirth = saveData[plr.UserId].rebirth or 0
			saveData[plr.UserId].inventory = saveData[plr.UserId].inventory or {1,}
			saveData[plr.UserId].hotbar = saveData[plr.UserId].hotbar or {1,}
			saveData[plr.UserId].pack = saveData[plr.UserId].pack or 20
		end

	else
		warn(plr.Name.."'s data store is not connected")
		plr:Kick("Rejoin, your data didn't load")
	end

	
	packID.Value = saveData[plr.UserId].pack
	taps.Value = saveData[plr.UserId].taps
	cash.Value = saveData[plr.UserId].cash

	for i,id in pairs(saveData[plr.UserId].inventory) do
		if itemTabl[id].itemType == "part" then
			local tool = parts:FindFirstChild(itemTabl[id].name):Clone()
		
			tool.Parent = inventory
		end
		if itemTabl[id].itemType == "pack" then
			local pack = packs:FindFirstChild(itemTabl[id].name):Clone()
		
			pack.Parent = inventory
		end
	end
	
	for i,id in pairs(saveData[plr.UserId].hotbar) do
		if itemTabl[id].itemType == "part" then
			local tool = parts:FindFirstChild(itemTabl[id].name):Clone()
			local toolReplica = parts:FindFirstChild(itemTabl[id].name):Clone()
		
			local toolScript = scripts.PartScript:Clone()
			local toolLocal = scripts.PartAnimations:Clone()
			
			toolScript.Parent = tool
			toolLocal.Parent = tool
			
			toolScript.Enabled = true
			toolLocal.Enabled = true
			
			tool.Parent = plr.Backpack
			toolReplica.Parent = hotbar
		end
		if itemTabl[id].itemType == "pack" then
			local pack = packs:FindFirstChild(itemTabl[id].name):Clone()
	
			pack.Parent = hotbar
		end
	end
	local packID = saveData[plr.UserId].pack
	local pack = packs:WaitForChild(itemTabl[packID].name):Clone()
	
	local char = plr.Character
	local torso = char:WaitForChild("Torso")
		
	local weld = Instance.new("Weld")
	weld.Name = "PackJoint"
	weld.Parent = torso
	weld.Part0 = torso
	weld.Part1 = pack:WaitForChild("Bag")
	weld.C0 = CFrame.new(0,0,0.95)
			
	pack.Name = "Pack"
	pack.Parent = char
	
	event.Owned:FireClient(plr, saveData[plr.UserId].inventory)
end)

local 1:

local plrs = game:GetService("Players")
local uis = game:GetService("UserInputService")
local tweenServ = game:GetService("TweenService")
local starterGui = game:GetService("StarterGui")
local lighting = game:GetService("Lighting")

local rStore = game:GetService("ReplicatedStorage")
local maps = rStore:WaitForChild("Maps")
local event = rStore:WaitForChild("Events")
local loEvent = rStore:WaitForChild("LocalEvents")


local idSystem = require(rStore:WaitForChild("IDSystem"))

local shopInt = loEvent:WaitForChild("shopInt")

local plr =  plrs.LocalPlayer
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local camTween

local char = plr.Character
local hum = char:WaitForChild("Humanoid")

local leaderstats = plr:WaitForChild("leaderstats")
local taps = leaderstats.Thingies
local cash = leaderstats.Wealth

local gui = plr.PlayerGui
local shopGui = gui.ShopGui
local leftButton = shopGui.Left
local rightButton = shopGui.Right
local buyButton = shopGui.Buy
local exitButton = shopGui.Exit
local flipButton = shopGui.Flip

local title = shopGui.Title
local price = shopGui.Price
local power = shopGui.Power



local shop = maps:WaitForChild("ShopView"):Clone()
local parts = shop:WaitForChild("Parts")
local packs = shop:WaitForChild("Packs")
local inShop = false
local onBuy = false
local flip = false
local option = 1
local pressed = 0
local poor = false
local lastCamPos = cam.CFrame

local itemTabl = idSystem.itemTabl

local textStuf = require(starterGui:WaitForChild("textStuf"))
	
local function optionGui()
	title.Text = itemTabl[option].name
	price.Text = "Price: $".. textStuf.aberviate(itemTabl[option].price)
	
	if flip then
		flipButton.Text = "Parts (S)"
		power.Text = "Space: ".. textStuf.aberviate(itemTabl[option].power)
	else
		flipButton.Text = "Packs (S)"
		power.Text = "Power: ".. textStuf.aberviate(itemTabl[option].power)
	end
end


local function cameraPan() 
	pressed = 0
	poor = false
	
	if not flip then
		local part = parts["option".. tostring(option)].CamAnchor
		camTween = tweenServ:Create(cam, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CFrame = part.CFrame * CFrame.Angles(math.rad(-15),0,0) + Vector3.new(0,2,5)})
		camTween:Play()
	else
		local pack = packs["option".. tostring(option)].CamAnchor
		camTween = tweenServ:Create(cam, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CFrame = pack.CFrame * CFrame.Angles(math.rad(-15),0,0) + Vector3.new(0,2,-5)})
		camTween:Play()
	end
	
end


local function purchaseGui()
	if itemTabl[option].owned then
		buyButton.BackgroundColor3 = Color3.new(0,0,0)
		buyButton.Text = "Owned"
		
		buyButton.Active = false
		buyButton.Interactable = false
		return
	else
		buyButton.Text = "Purchase?"
		buyButton.BackgroundColor3 = Color3.new(0, 255, 0)
		
		buyButton.Active = true
		buyButton.Interactable = true
	end
end


local function purchase()
	if itemTabl[option].owned then
		return
	end
	buyButton.BackgroundColor3 = Color3.new(0,1,0)
	buyButton.Text = "Purchase?"
	pressed += 1
	
	if poor then
		poor = false
		pressed = 0
	end
	
	if pressed == 1 then
		buyButton.Text = "Confirm?"
	elseif pressed >= 2 then
		if cash.Value >= itemTabl[option].price then
			print(plr.Name.." Bought ".. itemTabl[option].name)
			event.Buy:FireServer(option)

			pressed = 0
			buyButton.BackgroundColor3 = Color3.new(0,0,0)
			buyButton.Text = "Owned"
			
			buyButton.Active = false
			buyButton.Interactable = false
			
			mouse.Icon = ""
			
			return
		else 
			pressed = 0
			poor = true

			buyButton.Text = "ur broke"
			buyButton.BackgroundColor3 = Color3.new(255,0,0)
		end

	end
end


local function flipOptions()
	if flip then
		flip = false
		option -= 19
	else
		flip = true
		option += 19
	end
	
	optionGui()
	purchaseGui()
	
	cameraPan()
end


event.Owned.OnClientEvent:Connect(function(inventoryTabl)
	print("local 1 recieved")
	for i,id in ipairs(inventoryTabl) do
		itemTabl[id].owned = true
	end
	
	if itemTabl[option].owned then
		buyButton.BackgroundColor3 = Color3.new(0,0,0)
		buyButton.Text = "Owned"
	else
		buyButton.BackgroundColor3 = Color3.new(0, 255, 0)
		buyButton.Text = "Purchase?"
	end
end)


shopInt.Event:Connect(function()
	inShop = true
	
	hum.WalkSpeed = 0
	shop.Parent = workspace
	
	starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

	if itemTabl[option].owned then
		buyButton.BackgroundColor3 = Color3.new(0,0,0)
		buyButton.Text = "Owned"
	else
		buyButton.BackgroundColor3 = Color3.new(0, 255, 0)
		buyButton.Text = "Purchase?"
	end
	
	lastCamPos = cam.CFrame
	
	shopGui.Enabled = true
	cam.CameraType = Enum.CameraType.Scriptable

	optionGui()
	
	if flip then
		cam.CFrame = packs:WaitForChild("option".. tostring(option)):WaitForChild("CamAnchor").CFrame * CFrame.Angles(math.rad(-15),0,0) + Vector3.new(0,2,-5)
	else
		cam.CFrame = parts:WaitForChild("option".. tostring(option)):WaitForChild("CamAnchor").CFrame * CFrame.Angles(math.rad(-15),0,0) + Vector3.new(0,2,5)
	end
	
end)


uis.InputBegan:Connect(function(input, gpe)
	if not gpe and inShop then
		if inShop and input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.A then
			
			if input.KeyCode == Enum.KeyCode.D then
			if not flip then
				option += 1
				if option > 19 then
					option = 1
				end
			else
				option -= 1
				if option < 20 then
					option = 38
				end
			end
		elseif input.KeyCode == Enum.KeyCode.A then
			if not flip then
				option -= 1
				if option < 1 then
					option = 19
				end
			else
				option += 1
				if option > 38 then
					option = 20
				end
			end
		end
		
		optionGui()
		purchaseGui()
			
		cameraPan()
		
		end
		if input.KeyCode == Enum.KeyCode.S then
			if not shopInt then return end
			
			flipOptions()
		end
	end
end)


rightButton.MouseButton1Down:Connect(function()
	if not inShop then return end
	
	if not flip then
		option += 1
		if option > 19 then
			option = 1
		end
	else
		option -= 1
		if option < 20 then
			option = 38
		end
	end
	
	optionGui()
	purchaseGui()
	
	cameraPan()
end)


leftButton.MouseButton1Down:Connect(function()
	if not inShop then return end
	
	if not flip then
		option -= 1
		if option < 1 then
			option = 19
		end
	else
		option += 1
		if option > 38 then
			option = 20
		end
	end
	
	optionGui()
	purchaseGui()
	
	cameraPan()
end)


buyButton.Activated:Connect(function()
	if not inShop then return end
	
	purchase()
end)


exitButton.Activated:Connect(function()
	inShop = false
	
	hum.WalkSpeed = 16
	
	if camTween then
		camTween:Cancel()
	end
	
	cam.CameraType = Enum.CameraType.Custom
	cam.CFrame = lastCamPos
	shopGui.Enabled = false
	
	starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end)


flipButton.Activated:Connect(function()
	if not shopInt then return end
	
	flipOptions()
end)

local 2:

local plrs = game:GetService("Players")
local debris = game:GetService("Debris")
local uis = game:GetService("UserInputService")
local tweenServ = game:GetService("TweenService")
local starterGui = game:GetService("StarterGui")
local lighting = game:GetService("Lighting")

local rStore = game:GetService("ReplicatedStorage")

local stuff = rStore:WaitForChild("Stuff")
local parts = stuff:WaitForChild("Parts")
local packs = stuff:WaitForChild("Packs")

local maps = rStore:WaitForChild("Maps")
local event = rStore:WaitForChild("Events")
local uEvent = rStore:WaitForChild("UEvents")

local inventory = rStore:WaitForChild("LocalInventory")

local modls = rStore:WaitForChild("Models")
local oldModel
local spinTween
local spinAng = 0

local idSystem = require(rStore:WaitForChild("IDSystem"))
local plrData = event.GetData:InvokeServer()

local plr =  plrs.LocalPlayer
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera

local char = plr.Character

local pack = char:WaitForChild("Pack")
local packID = pack:WaitForChild("ID").Value

local leaderstats = plr:WaitForChild("leaderstats")
local taps = leaderstats.Thingies
local cash = leaderstats.Wealth

local plrGui = plr.PlayerGui
local regGui = plrGui:WaitForChild("RegularGui")
local statFrame = regGui.GuiFrame
local cashDisplay = statFrame.CashDisplay
local tapDisplay = statFrame.TapsDisplay
local spaceBar = statFrame.SpaceBar
local bar = spaceBar.Bar
local spaceBarTaps = spaceBar.Taps
local spaceBarStorage = spaceBar.Storage

local StuffButton = statFrame.StuffButton
local petButton = statFrame.PetsButton

local inventoryFrame = regGui.InventoryFrame
local contents = inventoryFrame.Contents
local exitClip = inventoryFrame.ExitClippingFrame
local info = inventoryFrame.Info

local partFrame = contents.PartsFrame
local packFrame = contents.PacksFrame

local packGrid = packFrame.UIGridLayout
local partGrid = partFrame.UIGridLayout

local viewFrame = inventoryFrame.ViewFrame
local viewPort = viewFrame.ViewportFrame
local viewCam = Instance.new("Camera")
viewCam.Name = "ViewportCam"
viewCam.Parent = viewPort
local tweenVal = Instance.new("IntValue")
tweenVal.Name = "tweenVal"
tweenVal.Parent = viewCam

viewPort.CurrentCamera = viewCam
regGui.Enabled = true

--Funcs

local function cellSetup()
	local partGridOffset = UDim2.new(0,(partGrid.CellSize.X.Scale * partFrame.AbsoluteSize.X),0,(partGrid.CellSize.Y.Scale * partFrame.AbsoluteSize.Y))
	local packGridOffset = UDim2.new(0,(packGrid.CellSize.X.Scale * packFrame.AbsoluteSize.X),0,(packGrid.CellSize.Y.Scale * packFrame.AbsoluteSize.Y))
	
	partGrid.CellSize = partGridOffset
	packGrid.CellSize = packGridOffset
end

local function sizeAdjust()
	local absPartSize = partGrid.AbsoluteContentSize
	local absPackSize = packGrid.AbsoluteContentSize
	
	if absPackSize == Vector2.new(0,0) then
		absPackSize = Vector2.new(200,400)
	end
	if absPartSize == Vector2.new(0,0) then
		absPackSize = Vector2.new(200,400)
	end
	
	partFrame.Size = UDim2.new(1,0,0.025,absPartSize.Y)
	packFrame.Size = UDim2.new(1,0,0.025,absPackSize.Y)
end


--Setup

cellSetup()
sizeAdjust()

--Events

event.Owned.OnClientEvent:Connect(function(InventoryDict)
	print("local 2 recieved")
	inventory:ClearAllChildren()
	for i, ID in ipairs(InventoryDict) do
		local itemType = idSystem.itemTabl[ID].itemType
		if itemType == "part" then
			local itemClone = parts:WaitForChild(idSystem.itemTabl[ID].name):Clone()
			itemClone.Parent = inventory
		end
		if itemType == "pack" then
			local itemClone = packs:WaitForChild(idSystem.itemTabl[ID].name):Clone()
			itemClone.Parent = inventory
		end
	end
end)

--Testy stuff
regGui:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
	sizeAdjust()
end)

--Updating ViewportCam w Tweenval
tweenVal.Changed:Connect(function()
	local tau = 2 * math.pi
	local radius = 3
	local A = math.rad(tweenVal.Value)
	viewCam.CFrame = CFrame.lookAt(Vector3.new(math.sin(A)*radius, 0, math.cos(A)*radius), Vector3.new())
end)
type or paste code here
1 Like

It’s possible that either script is yielding long enough that the event is missed. You can determine this by placing a print call right before RemoteEvent:FireClient is called, then by adding a breakpoint prior to both RemoteEvent.OnClientEvent:Connect calls. Investigate what’s taking up the that time. In general, a better design would be to use a RemoteFunction that enables clients to request data from the server when they’re ready to receive it

3 Likes

yeah that makes sense, thank you very much and have a splendid day :+1::+1:

Just a little closing statement.

Probably the sheer amount of “WaitForChild” functions are yielding the scripts and @Ziffixture had a better idea to just make a remote function. Funnily enough, I literally already made a remote function to give data to the client so yeah… to conclude ig just use functions :tangerine:

Mind you, the server does not need to use Instance:WaitForChild for any instance that exists in the edit data model (Roblox Studio). When Roblox starts a game server, it clones the edit data model, then streams it to the client. Since Scripts run on this server-sided data model clone, all instances will already exist for those Scripts. The client has to await them due to the fact its copy of the data model has to be downloaded over time. The only time you’ll use WaitForChild on the server is for instances created during runtime

2 Likes

oh really? thats really useful thanks again :+1:

1 Like