FIGHT SYSTEM


SKIP 4 (WILL DO LATER)


🧱 STEP 1: Create the RemoteEvent

This is used to tell the server when a player punches.

  1. In ReplicatedStorage, right-click > Insert Object > RemoteEvent

  2. Rename it to: PunchEvent

Done! You now have a remote signal to tell the server “I punched!”


💻 STEP 2: Set Up Input Detection (PC, Mobile, PS4)

Create a LocalScript that listens for input using ContextActionService.

🔹 Where to place it:

  • Put this in: StarterPlayerScripts

🔹 Script: PunchInputHandler

local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PunchEvent = ReplicatedStorage:WaitForChild("PunchEvent")

local function handlePunch(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		PunchEvent:FireServer()
	end
	return Enum.ContextActionResult.Sink
end

ContextActionService:BindAction("Punch", handlePunch, true,
	Enum.KeyCode.E,                             -- Keyboard
	Enum.UserInputType.MouseButton1,            -- Mouse (PC)
	Enum.UserInputType.Touch,                   -- Mobile
	Enum.KeyCode.ButtonA                        -- PS4 controller
)

✅ This now allows all devices to punch using:

  • PC: E or Left Click

  • Mobile: Touch anywhere

  • PS4: Button A (X)


📱 STEP 3: Add Touch Button for Mobile (Optional but Recommended)

Mobile users need a visual punch button.

🔹 Where to add:

  • In StarterGui, insert a ScreenGui

  • Inside the ScreenGui, insert a TextButton

  • Set its:

    • Size to {0.15, 0}, {0.15, 0} (15% screen size)

    • Position to {0.8, 0}, {0.8, 0} (bottom right corner)

    • Text to PUNCH

    • Name it PunchButton

🔹 Add a LocalScript inside the button:

local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local PunchEvent = ReplicatedStorage:WaitForChild("PunchEvent")

-- Only show on mobile
button.Visible = UserInputService.TouchEnabled

button.MouseButton1Click:Connect(function()
	PunchEvent:FireServer()
end)

✅ Now mobile users can punch with a button too.


🛠 STEP 4: Add Simple Server Response

Now the server will respond when a player punches — for now, just print.

🔹 Where to add:

  • In ServerScriptService, insert a Script

  • Call it: PunchServerHandler

🔹 Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PunchEvent = ReplicatedStorage:WaitForChild("PunchEvent")

PunchEvent.OnServerEvent:Connect(function(player)
	print(player.Name .. " punched!")
end)

✅ This confirms the system works. You’ll see it print in the output whenever a punch happens.


STEP 5: Test All Platforms

Test with Emulator Tools in Roblox Studio:

  1. Click Test > Device and try:

    • 📱 Phone (Tap screen + Punch button)

    • 💻 PC (Click or press E)

    • 🎮 Console (use controller if you have one)

  2. Watch the Output for “PlayerName punched!” — if it appears, you're golden.