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

How can I make a brick do this function?

So I am making a game where you can Sword Fight and get Player Points for each kill. I don't want there to be a map. I am trying to make it to where you step on a certain plate and then you can kill each other. I came here to ask how I would go about making a brick to where you cannot kill each other with swords when your on it. The reason I have not made one yet is because I don't want that ugly FF around them I just want them to immune to getting damaged while on this brick. Also I had made one to where it gives the unlimited health but the bar changed to yellow like when you have GOD mode on but I don't like that I want it to stay green. This is not a request you do not have to help neither did I ask for you to make anything so please don't claim that it is! Have a good day!! ^_^

1 answer

✓ Accepted answer

You would probably need to edit the sword script. In the blow(hit) function you need to check if the player's torso is close to the brick using magnitude. I would not recommend a Touched or TouchEnded event due to the fact that many players will be one the brick on once. However, note that magnitude will find the length between the center of the two bricks, so if you have a large brick you may need to play with the magnitude a little bit. It will take some trial and error.

You will also need to name the brick something other than 'Part', so we can access it. I'll assume it is named 'KillingMat'.

function blow(hit)
	if (hit.Parent == nil) then return end -- happens when bullet hits sword

	local humanoid = hit.Parent:findFirstChild("Humanoid")
	local vCharacter = Tool.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)
	local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
	if humanoid~=nil and humanoid ~= hum and hum ~= nil then
		-- final check, make sure sword is in-hand

		if (humanoid.Parent.Torso.Position - workspace.KillingMat.Position).magnitude > 30 then return end --Stops the function if the distance from the hit's torso to the mat is greater than 30 studs. You will need to edit the 30 studs depending on the size of the brick.	

		local right_arm = vCharacter:FindFirstChild("Right Arm")
		if (right_arm ~= nil) then
			local joint = right_arm:FindFirstChild("RightGrip")
			if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
				tagHumanoid(humanoid, vPlayer)
				humanoid:TakeDamage(damage)
				wait(1)
				untagHumanoid(humanoid)
			end
		end


	end
end

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