Remote Event Error - Expected identifier when parsing variable name, got 'true'

Hey there, I am new to this field of scripting. It’s been untouched for me because for a while now I’ve dreaded having to deal with the problems that it brings up within my understanding. I have already extensively done a lot of GUI scripting a while now, that’s my comfortable spot with scripting, but I wanted to go out of my way and add another mechanic to one of the games I’m developing that require remote events to be possible.

I’m wanting to make an event in where when the player presses the shift key, a part is put at the position of the torso that is a bubble, a lot like the one in the Smash Bros’ games, as a shield. The bubble has not been added yet because I am having issues with the basic functionality of the event firing correctly with a simple string, which errors as down below.

ServerScriptService.BubbleServer:4: Expected identifier when parsing variable name, got 'true'

“True” and “False” in the server script are underlined red.

I have looked up tons of tutorials and documentation already on how to do this, so I am pretty well informed and already spent a few hours trying to find the problem.

The way I want to do this is to have two arguments for two different fire events; one true, one false. The true event will fire when the shift key is pressed down, the false event will trigger when the shift key is released. For both events, for now, I want them to print the player’s name and true or false to verify it works-- in which case right now does not work.

It’s probably a very simple and silly mistake, but it’s all a part of scripting. Hope somebody can help me out.

The remote event itself is located under ReplicatedStorage.Remotes, and is called BubbleHandler.
The local script is under StarterGui.
The server script is under ServerScriptService.

LOCAL

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteBubble = ReplicatedStorage.Remotes.BubbleHandler
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input) -- Input Began checks if the player presses anything and fires whenever the player does so.
if input.KeyCode == Enum.KeyCode.LeftShift then -- This detects for a "left shift" press.
print("[Bubble Start] Client Fired!")
remoteBubble:FireServer(true)
end
end)
UserInputService.InputEnded:Connect(function(input) -- Fires when input ended
print("[Bubble End] Client Fired!")
remoteBubble:FireServer(false)
end)

SERVER

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteBubble = ReplicatedStorage.Remotes.BubbleHandler

remoteBubble.OnServerEvent:Connect(function(player, true)
	print (player.name.." had fired the event. true")
end)

remoteBubble.OnServerEvent:Connect(function(player, false)
	print (player.name.." had fired the event. false")
end)

There are some problems with both of your scripts (not talking about the error). But the reason why you are getting this error, though, is because true and false are already in-built functions. You have to name the argument to something else, not true or false.

Here are your fixed scripts:

Local Script:

local RP = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local BubbleEvent = RP:WaitForChild("Remotes").BubbleHandler

UIS.InputBegan:Connect(function(input, typing) -- 'typing' is when/if a player is chatting or typing in a textbox
	if typing then
		return
	end
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		BubbleEvent:FireServer(true)
	end
end)

UIS.InputEnded:Connect(function(input, typing)
	if typing then
		return
	end
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		BubbleEvent:FireServer(false)
	end
end)

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BubbleEvent = ReplicatedStorage:WaitForChild("Remotes").BubbleHandler

BubbleEvent.OnServerEvent:Connect(function(player, info) -- 'info' is just a custom name for 'true' or 'false' arguments
	if info == true then 
		print(player.Name.." had fired the event. True")
		-- your stuff
	else -- if its not true (technically if its false)
		print(player.Name.." had fired the event. False")
	end
end)
1 Like

Thanks a ton! Especially for the added fixes.

1 Like

I can explain to you what the problems were so you can have a better understanding and fix these types of problems if you encounter them in the future.

First problem:
You are mentioning when a player immediately presses a key on their keyboard (InputBegan), and you detect if the LeftShift key was pressed, then you fire the remote event, which is perfectly fine. However, when you are mentioning when the player pressed and let go of a key (InputEnded), you never mention which key was even let go of. So if you press and let go of any key on your keyboard, the remote event will always fire. You have to mention which key was pressed and let go when calling the InputEnded event, even though you already done that in InputBegan (because they are 2 separate events).

Second problem:
In your server script, you are calling the OnServerEvent event twice, although this is not what you do. Since you are only firing one remote event, you only call OnServerEvent once. Name the second argument whatever you want, but not the function names (just like true or false), otherwise it will give you an error (just like what you have already encountered). You instead just want to make an if statement saying whether the second argument is equal to true or equal to false (as I have just done in the code I provided). And then you do your stuff.

I hope this is understandable. And you are very welcome, happy to help!

1 Like

Again, thanks a ton!
I’m using this to make a very very large scale project with a set of other developers including the developer of Lumber Tycoon 2 Remade and several large warclan developers that I am in close relation with.

It will be put to good use.

The entire game is going to be a thoroughly made Smash Brothers/Brawlhalla genre game using different ROBLOX culture characters as the champions within the game, with proper side scrolling and an already implemented camera system that ensures every character on the screen is in focus. Jump-through platforms are already sorted out, double jumping, an entirely different instanced main menu, and so many other features that make that genre of game definitive. I have yet to see one of these kinds of games exist on ROBLOX that come close to doing it correctly, and the only one I’ve ever seen come close uses the default ROBLOX camera, only has one stage, and believe it or not was on the front page more than once.

1 Like