Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script Won't Print Statement After Pressing Shift Key?

So, I've been working on a script that activates increases your speed when you press Left Shift. I've recently been trying to just get print statements to work so that I know something being transferred over the RemoteEvent I set up. Well, the print statement doesn't work, and the output is left blank. So, here's the code inside StarterPlayerScripts:

local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage:WaitForChild("SprintEvent")

if userInputService.InputBegan and userInputService.KeyboardEnabled then
	userInputService.InputBegan:connect(function(inputObject)
	if inputObject == Enum.KeyCode.LeftShift then		
			event:FireServer("SprintBegan")
		end	
	end)
elseif userInputService.InputEnded and userInputService.KeyboardEnabled then	
	userInputService.InputEnded:connect(function(inputObject)
		if inputObject == Enum.KeyCode.LeftShift then						
			event:FireServer("SprintEnded")
		end	
	end)
end	

and here's the test script inside ServerScriptService:

local sprintEvent = game.ReplicatedStorage:WaitForChild("SprintEvent")

sprintEvent.OnServerEvent:connect(function(...)
	local tuple = {...}
	if tuple[1] == "SprintBegan" then
		print("Sprint Began")
	elseif tuple[1] == "SprintEnded" then
		print("Sprint Ended")
	end
end)

1 answer

✓ Accepted answer

OnServerEvent always takes the player as its first argument, THEN the other arguments.

local sprintEvent = game.ReplicatedStorage:WaitForChild("SprintEvent")

sprintEvent.OnServerEvent:connect(function(player, ...)
    local tuple = {...}
    if tuple[1] == "SprintBegan" then
        print("Sprint Began")
    elseif tuple[1] == "SprintEnded" then
        print("Sprint Ended")
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.