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

Can someone add --s to this template so I know how to edit it?

A guy on the forums gave me this script template, but he didn't add and headings so I could edit it easier (I'm a newbie at scripting). Could someone do so? Thanks!

local uis = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local human = char.Humanoid
local mouse = player:GetMouse()
local anim = script:WaitForChild('Animation')

uis.InputBegan:connect(function(input,event)
	if event then return end
	if input.KeyCode == Enum.KeyCode.Q then
		local track = human:LoadAnimation(anim)
		if mouse.Target then
			local target =  mouse.Target.Parent:FindFirstChild('Humanoid')
			if target then
				track:Play()
				target.Humanoid:TakeDamage(10)
			end
		end
	end
end)

1 comment

0

Just for future reference, '--'s are called comments.

1 answer

✓ Accepted answer

Sure.

local uis = game:GetService('UserInputService') --// Get UserInputService.
local player = game.Players.LocalPlayer --// Get the player.
local char = player.Character or player.CharacterAdded:wait() --// Get the character (if it doesn't exist, wait for the character).
local human = char:WaitForChild('Humanoid') --// Get the character's humanoid.
local mouse = player:GetMouse() --// Get the mouse.
local anim = script:WaitForChild('Animation') --// Get the animation.

uis.InputBegan:connect(function(input,event)
    if event then return end --// If the input was a game processed event (like chat-related stuff), then return.
    if input.KeyCode == Enum.KeyCode.Q then --// If Q was pressed..
        local track = human:LoadAnimation(anim) --// Load the animation into the humanoid.
        if mouse.Target then --// If the mouse is pointing to something in the workspace.
            local target =  mouse.Target.Parent:FindFirstChild('Humanoid') --// Get the target's humanoid.
            if target then --// If the target has a humanoid..
                track:Play() --// Play the track.
                target.Humanoid:TakeDamage(10) --// Make the target take 10 damage.
            end
        end
    end
end)

Some of the stuff you should read up on:

UserInputService, Mouse, & Humanoids.

In the future, it would be preferable if you would simply do your own research on the wiki, and then ask a question here if you still don't understand. Hope this helped.

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