How can I use Remote Events to change this local script into a normal script?

I have gotten everything working perfectly in this script however, I didn’t Realise putting it in a local script would make it so that the other player doesn’t really take damage but on my screen it does.

how can I create a normal script using this part of a local script with Remote events as it use UserInputService so i cannot just change it from local script to Server script easily.

UIS.InputBegan:Connect(function(input)
	wait(0.01)
	if input.KeyCode == Enum.KeyCode.E then
		if PunchLanded == true then
			if not CD then
				CD = true
				local Event = nil 
				local Hitbox = RS.GroundPunchHB:Clone()
				Hitbox.CFrame = HRP.CFrame * CFrame.new(0,-3,0)
				Hitbox.Parent = workspace

				Event = Hitbox.Touched:Connect(function(hit)
					local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
					if hum and hum.Parent.Name ~= Plr.Name then
						if not Debounce then
							Debounce = true
							local Indicator = RS:WaitForChild("DmgIndicator")
							if Indicator then
								if PunchLanded == true then
									wait(0.1)
									local gui = Indicator:Clone()
									gui.Parent = hit.Parent.HumanoidRootPart
									gui.Shadow.Text = "-"..tostring(damage)
									gui.Shadow.Damage.Text = "-"..tostring(damage)
									gui.StudsOffset = Vector3.new(math.random(-2,2), math.random(-2,2), math.random(-2,2))
									local TweenDamageGui = game:GetService("TweenService"):Create(gui, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, false), {Size = UDim2.new(1.5, 0 , 1.5 , 0)})
									TweenDamageGui:Play()
									game.Debris:AddItem(gui, 1.5)
									wait(0.1)
									hum:TakeDamage(damage)
									wait(0.3)
									Debounce = false
								end
							end
						end
					end
				end)
				local weld = Instance.new("ManualWeld")
				weld.Part0 = Hitbox
				weld.Part1 = HRP
				weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
				weld.Parent = weld.Part0
				wait(0.1)
				Event = nil
				Hitbox:Destroy()
				wait(3)
				CD = false
			end
		end
	end
end)

Thanks to anyone that helps

Btw. I didn’t only try getting other people to do it ive been looking and testing for quite a while.

I would recommend you instead, use a mix of local and server side scripts for this.

Thats what i mean using Remote events for it since it has userinputservice. Event:FireServer() in local with all the things i need in the local and Onserverevent in Server Script

Anyone??

( Filler Text Filler Text Filer Text )

Here’s how you can accomplish this:

You can call on a RemoteEvent through ReplicatedStorage, as this will replicate any descendants of the object to the server and the client. Here’s the code game:GetService("ReplicatedStorage").Event:FireServer()

Then, create a regular Script in ServerScriptService, and enter this code:

local rs = game:GetService("ReplicatedStorage")

rs.Event.OnServerEvent:Connect(function()
-- Enter server-side code here, you may need to reformat the code to get the correct result
end)

Make sure to reformat the code to work on the server side, which may include adding variables, such as this:

event.OnServerEvent:Connect(function(player, variable, variable2) -- takes in a variable from the FireServer method, and the first variable is always the client that fired the event.

end)

event:FireServer(variableToTransfer, variableToTransfer2) -- send over data from the client to the server

Hope this helps!

Yes it did thanks it works now :smiley:

1 Like