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

Someone help me make this script how to add a key to press activate?

Someone had made this script for me which if Player1 touch Player2 they take damage over time. So i was wondering if someone can double check it cause i tried to add a key press button like e to activate then i think i screwed it all up. So can someone please double check the script and add a press e to active?

settings = { --This is a table, this table will store all the variables that you can change.
damageTime = 12, -- How many times It will damage the player
inbetweenTime = .7, -- The time you have to wait until It damages again
damage = 10, -- How much damage it will do
debounce = false, -- Not recommended to change this
}
for i,v in pairs(game.Players:GetChildren()) do --[[ Grab all the players in the player service --]]
workspace[v.Name].Touched:Connect(function(hit) --[[ This is a function which will fire when it is touched --]]
if hit.Parent:FindFirstChildOfClass('Humanoid') then --[[ This will check if it hits something w/ a humanoid --]]
if not settings.debounce then -- Checks if debounce is false
settings.debounce = true
for i = 1,settings.damageTime do -- This is a for loop that will loop a certain amount of times
hit.Parent:FindFirstChildOfClass('Humanoid'):TakeDamage(settings.damage) --[[ this will take damage--]]
wait(settings.inbetweenTime) -- this will wait for the time classified in settings.
end
settings.debounce = false
wait(7)
end
end
end)

1 answer

✓ Accepted answer

I made some mistakes in the script I sent you for this so this is the little more fixed version and the key press version. Don't hesitate to ask questions about this or tell me if it doesn't work since I haven't tested it.

Make sure that this is in a LOCAL SCRIPT and not a SERVER SCRIPT and it's located in StarterGui or StarterPlayer > StarterPlayerScripts

Modified Version:

local settings = { --This is a table, this table will store all the variables that you can change.
damageTime = 6, -- How many times It will damage the player
inbetweenTime = .5, -- The time you have to wait until It damages again
damage = 10, -- How much damage it will do
debounce = false,
hitDebounce = false,
timeUntilPunch = 7, -- Change this to the time you want it to wait until you can punch again
}


	repeat wait() until game.Players.LocalPlayer.Character
function onKeyPress(inputObject,gameProcessedEvent)
	settings.debounce = false
    if inputObject.KeyCode == Enum.KeyCode.E and not settings.debounce then
	settings.debounce = true
game.Players.LocalPlayer.Character.HumanoidRootPart.Touched:Connect(function(hit) --[[ This is a function which will fire when it is touched, make sure to put the player you want in the brackets w/ .HumanoidRootPart  --]]
if hit.Parent:FindFirstChildOfClass('Humanoid') and settings.debounce == true then --[[ This will check if it hits something w/ a humanoid --]]
for i = 1,settings.damageTime do
	if not settings.hitDebounce then
		settings.hitDebounce = true
	hit.Parent:FindFirstChildOfClass('Humanoid'):TakeDamage(settings.damage) -- this will take damage
	wait(settings.inbetweenTime) -- this will wait for the time classified in settings.
	settings.hitDebounce = false
	end
end
wait(settings.timeUntilPunch)
settings.debounce = false
end
end)
end
	end

game:GetService('UserInputService').InputBegan:Connect(onKeyPress)

4 comments

0

Im going to try it out right now. Mind if i could friend you?

0

I don't mind

0

If you want you can friend me on my main https://www.roblox.com/users/74254309/profile

0

k

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