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

How to create a pvp system like in Blox Fruits?

I'm creating a pvp system like in blox fruits. I created an accessory with a handle that damages any player in range when my weapon tool is activated. I used Touched event to detect players but when I hit a player, the damage is higher than expected although I have added a debounce and set the handle's CanTouch property to false. How can I fix this? Here is my code:

char:WaitForChild("DamagingPart").Handle.Touched:Connect(function()
	local currentDamagedPlayer
	print("abc")
	for _, child in pairs(char.DamagingPart.Handle:GetTouchingParts()) do
		if (game.Players:FindFirstChild(child.Parent.Name or child.Parent.Parent.Name) and not (game.Players.LocalPlayer.Name == (child.Parent.Name or child.Parent.Parent.Name)) and game.Players[child.Parent.Name].Team ~= game.Players.LocalPlayer.Team) and child.Parent.Name ~= currentDamagedPlayer then
			currentDamagedPlayer = game.Players[child.Parent.Name or child.Parent.Parent.Name].Name
			local randomDamage = math.random(tool.Damage.Value - 1, tool.Damage.Value + 1)
			game.ReplicatedStorage.WeaponInteraction:FireServer("Damage", game.Players[child.Parent.Name or child.Parent.Parent.Name], randomDamage)
			game.Players.LocalPlayer.PlayerGui.ScreenGui.AddWood.Text = randomDamage
			local position, onScreen = game.Workspace.CurrentCamera:WorldToScreenPoint(child.Parent.HumanoidRootPart.Position or child.Parent.Parent.HumanoidRootPart.Position)
			game.Players.LocalPlayer.PlayerGui.ScreenGui.AddWood.Position = UDim2.new(0, position.X, 0, position.Y)
			randomDamage = nil
			position, onScreen = nil, nil
			spawn(function()
				game.Players.LocalPlayer.PlayerGui.ScreenGui.AddWood.Visible = true
				game.Players.LocalPlayer.PlayerGui.ScreenGui.AddWood:TweenPosition(game.Players.LocalPlayer.PlayerGui.ScreenGui.AddWood.Position + UDim2.new(0, 0, 0, -50))
				wait(1)
				game.Players.LocalPlayer.PlayerGui.ScreenGui.AddWood.Visible = false
			end)
			currentDamagedPlayer = nil
			currentCutTree = nil
			char.DamagingPart.Handle.CanTouch = false
		end
	end
	char.DamagingPart.Handle.CanTouch = false
end)

I tried putting the "char.DamagingPart.Handle.CanTouch = false" under "local currentDamagedPlayer" but the for loop didn't run although the print function did. Why wouldn't the for loop work?

1 answer

Try placing "char.DamagingPart.Handle.CanTouch = false" after creating the for loop, tuanorn :)

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