Assigning values from a server script to a local script

Currently, I’ve written a combat script but all of it is on the client. I’m trying to rewrite part of it in a server script so that values such as damage or cooldown can not be changed by the client through exploits. I’m aware that I should use a RemoteEvent to communicate between server and client, but the issue is I’m unsure of what to do after that.

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == keybind then
		newHitbox1:SetPoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		newHitbox2:SetPoints(leftarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		newHitbox1.OnHit:Connect(function(hit, humanoid)
			newHitbox1:RemovePoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
			print("hit1")
			humanoid:TakeDamage(25)
		end)
		newHitbox2.OnHit:Connect(function(hit, humanoid)
			newHitbox2:RemovePoints(leftarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
			print("hit2")
			humanoid:TakeDamage(25)
		end)
		newHitbox1:HitStart(1)
		newHitbox2:HitStart(1)
	end
end)

Here’s a snippet of my code. For example, I’d like to have :SetPoint, :TakeDamage, and :HitStart all defined in a server script which then gets relayed to the client. If I’m not mistaken, this should make it impossible for the client to exploit, but please let me know if I’m mistaken and how I should go about ensuring that these values can’t be messed with!

Keep the UIS thing on client because it is only usable from the client, but do the take damage mechanics on the server and do checks on the server.

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == keybind then
		newHitbox1:SetPoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		newHitbox2:SetPoints(leftarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		newHitbox1.OnHit:Connect(function(hit, humanoid)
			newHitbox1:RemovePoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
			print("hit1")
                        -- Do the take damage code on the server and log it, use a Remote Event here
		end)
		newHitbox2.OnHit:Connect(function(hit, humanoid)
			newHitbox2:RemovePoints(leftarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
			print("hit2")
			-- Same here
		end)
		newHitbox1:HitStart(1)
		newHitbox2:HitStart(1)
	end
end)

I see what you’re saying but in my case I’m not sure that’s possible. The variable humanoid is defined as the local player’s character’s humanoid. I can’t access that through a server script. I can see how a Remote Event would help, but I’m trying to use it only to relay certain values to the client.

Let me know if I misunderstood something.

Well, you can access the humanoid on server script, because the RemoteEvent 's first argument is Player that fired the event. So you can just do Player.Character.Humanoid on server script.

You should probably do a check to make sure the player’s character still exists, just in case between the time the client fires the remote event and the server receives it, the character dissapears.

Yes, it’s necessary to check because it has some delay.

Can you elaborate on how that would be done? I took a crack at it but I think I messed up the argument.