Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Choobu 59
7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by
xEiffel 280 Moderation Voter
7 years ago
Edited 7 years ago

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)
0
Im going to try it out right now. Mind if i could friend you? Choobu 59 — 7y
0
I don't mind xEiffel 280 — 7y
0
If you want you can friend me on my main https://www.roblox.com/users/74254309/profile xEiffel 280 — 7y
0
k Choobu 59 — 7y
Ad

Answer this question