Nothing prints out in the console when firing an event (for 2 players)

Hello there,

i am making some sort of case battle system used by rblxwild (no gambling, ingame points)

The script explains everything so here you go. Thats the local script whenever you select a case and start the game (for example blue case.)

game.Players.PlayerAdded:Connect(function(Client) -- setting variable for client
script.Parent.MouseButton1Click:Connect(function()
	local propertiesData = { -- dont mind this
		["Amount of Rounds"] = 3,
		["Client"] = Client.Name
	}
		game.ReplicatedStorage.caseBattles.createCaseBattleBlue:FireServer(propertiesData, Client) -- creating properties and setting the parameter "client" as defined at line 1
	end)
end)	

This is the server script which handles the remote event:

local rep = game:WaitForChild("ReplicatedStorage")
local caseBattlesFolder = game:WaitForChild("ReplicatedStorage"):WaitForChild("caseBattles")


caseBattlesFolder.createCaseBattleBlue.OnServerEvent:Connect(function(Server, Dictionary, Client) -- Defining "Client" as the local player who created the game. Dont mind dictionary. Therefore defining "Server" as all players in the game
	local returned = false
	local template = Server.PlayerGui.UI.Dashboard.TextLabel.CaseBattles.ScrollingFrame.Template:Clone() -- Telling the server that a new game has been created and creating a new frame to inform people
	template.ImageLabel.Image = "rbxassetid://10910715327" -- Changing imagelabel to the hosts case selection.
	template.ImageLabel.TextLabel = "Host: "..Client.Name -- Setting Text as the Host from CLIENT.Name
	wait(0.01)
	local newVal = Instance.new("StringValue") -- Creating a new value to check which button the player has clicked, it could be that another player created the game and player clicked other button and it would show up at both guis as client and the other one. Well we dont want this so were defining this.
	newVal.Name = "USERDATA" -- Naming the value
	newVal.Value = Client.Name -- Setting as the Name of client
	newVal.Parent = template.ImageLabel.TextButton -- Parenting it into all player guis
	local reservedForClient = game.ServerStorage.CaseBattle:Clone() -- main case battle gui, reserving for client
	reservedForClient.Parent = Client.PlayerGui
	local reservedForPlayer = game.ServerStorage.CaseBattle:Clone() -- main case battle gui, reserving for expected player
	while wait() do -- waiting till a player joined and we get a response
		wait(.01)
		caseBattlesFolder.otherPLR.joinCaseBattle.OnServerEvent:Connect(function(Server, Val, expectedPLR)
			if Val.Value == newVal.Value then -- checking if the player has clicked our game by the value seen at the upper line
			print("returned = true") -- printing
			returned = true -- changing returned to true, so we get the response
			reservedForPlayer.Parent = expectedPLR.PlayerGui -- setting the gui reserved for expected player to expected player
			local image = game.Players:GetUserThumbnailAsync(expectedPLR.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420) -- changing image to thumbnail of expected player
			reservedForClient.Main.Content.secPLR.Image = image -- setting it as the expected plr profile picture
			reservedForClient.Main.Content.callBot.Visible = false -- disabling the call bot button
			reservedForPlayer.Main.Content.secPLR.Image = image -- the same just for the client
				reservedForPlayer.Main.Content.callBot.Visible = false -- the same just for the client
				wait(2) -- delay
				warn("Case battle starting") -- Response sucessful and the battle starts now.
			else
				-- nothing because we havent got a response yet
			end
		end)
	end
end)

It doenst print anything in the console, could someone help? Thanks!

Goodbye! :wave:

1 Like

I do not believe this in LocalScript works. If you want the local player, do:

Players.LocalPlayer

1 Like

Well, the player would need to see what player is creating the game. When i define LocalPlayer. for ex. Player: “player938” would see that “player938” created the game, therefore an other player created the game, not the player himself

2 Likes

If you wan to use PlayerAdded,

Do it in a script, not local script

1 Like

Let me try it.


2 Likes

Yooooo how did you bypass the limit?!?!?!

1 Like

magic

2 Likes

I tried it, it still doenst print out anything.

2 Likes
script.Parent.MouseButton1Click:Connect(function()
	local propertiesData = { -- dont mind this
		["Amount of Rounds"] = 3,
		["Client"] = game.Players.LocalPlayer.Name
	}
		game.ReplicatedStorage.caseBattles.createCaseBattleBlue:FireServer(propertiesData, Client) -- creating properties and setting the parameter "client" as defined at line 1
	end)

Replace the original localscript and see what happens

1 Like

did you define player in server script

1 Like

Yes. The parameter at the ServerEvent response as “Client”

1 Like

Hold on, @Florentin5434 is this localscript inside a physical button or gui button?

1 Like

I did

1 Like

GUI Button.

1 Like

i meant this line in other serverscript

1 Like

Yes, expectedPLR is the variable, the player who joined.
And i would think it would error if not defined

1 Like

Do a print check

Put a print() after the mouse button 1 click and see if anything prints

1 Like

you should define PLAYER first where the “Server” is in

1 Like

You’ve got some really scary nested connections here. In the first script every time a player joins you are connecting a remote event to fire on click, I think this is also back firing because it will not run for the local player until someone else joins. In the second script you are connecting to an event (caseBattlesFolder.otherPLR.joinCaseBattle.OnServerEvent) in an infinite loop!! If this event is fired the server will run this function a thousand times if the server has been running for a thousand seconds, worse yet it is connected every time the caseBattlesFolder.createCaseBattleBlue.OnServerEvent is fired. In total caseBattlesFolder.otherPLR.joinCaseBattle.OnServerEvent will each up so much CPU over time you game will stall and the server will crash.

You need to remove these connections one way or another, for the first script you just need to remove the surrounding player added connection. The second I am not sure, I do not know what it is trying to do.

1 Like

That would clone the gui into all player playerguis. It shows for everyone. We dont want that so we just defined the expected player.

1 Like