Trying to make a custom "engine" of my own

I’m currently making an engine where the movement, gravity, basically most things in the player and parts. The player currently moves like it’s ice, but with a nice amount of speed, and some jump power as the gravity is set to 35.07. I’m wondering how to make a flashlight come out the players head, as in surface light. Here’s my script.

local Density = 0.035
local Friction = 0
local Elasticity = 0
local FrictionWeight = 0
local ElasticityWeight = 0

function addNeccesities(char,hum)
	script.flashlight_use:Clone().Parent = char.Torso
	local SurfaceLight = Instance.new("SurfaceLight",char.Torso)
	SurfaceLight.Brightness = 1
end

game.Players.PlayerAdded:Connect(function(plr)
	if plr then
		plr.CharacterAdded:Connect(function()
			for _,v in pairs(workspace:WaitForChild(plr.Name):GetChildren()) do
				local char = workspace:WaitForChild(plr.Name)
				local hum = char.Humanoid
				hum.WalkSpeed = 23
				hum.JumpPower = 25
				hum.MaxSlopeAngle = 70
				addNeccesities(char,hum)
				if v:IsA("Part") then
                    v.CustomPhysicalProperties = PhysicalProperties.new(Density, Friction, Elasticity, FrictionWeight, ElasticityWeight)
				end
			end
		end)
	end
end)

script.RemoteEventPlayer.OnServerEvent:Connect(function(Player,Arg1,Arg2,Arg3)
	if Arg2 == "Flashlight" then
		if Arg3 == true then
			Player.Character.Torso.SurfaceLight.Enabled = true
		elseif Arg3 == false then
			Player.Character.Torso.SurfaceLight.Enabled = false
		end
	end
end)
``` Server

```lua
local uis = game:GetService("UserInputService")
local enabled = false
local plr = game.Players.LocalPlayer

uis.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.F and enabled == false then
		print("KeyPressed", true)
		enabled = true
		workspace.Engine.RemoteEventPlayer:FireServer("Flashlight",true)
	elseif enabled == true then
		enabled = false
		workspace.Engine.RemoteEventPlayer:FireServer("Flashlight",false)
		print("KeyPressed", false)
	end
end)
``` Client
1 Like