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

How can I put game:getservice in my tool?

Asked by 10 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

It's for a Anime RP game me and my friends dalton131, BuiltForNil have to use. I tried by just putting it in the tool but it won't work. When I try the tool out the blue words won't come out of my head :/ Idk whats wrong with it here's the whole script.

r = game:service("RunService")

local damage = 3 local slash_damage = 10

sword = script.Parent.Handle Tool = script.Parent

local SlashSound = Instance.new("Sound") SlashSound.SoundId = "rbxasset://sounds\swordslash.wav" SlashSound.Parent = sword SlashSound.Volume = .7

local LungeSound = Instance.new("Sound") LungeSound.SoundId = "rbxasset://sounds\swordlunge.wav" LungeSound.Parent = sword LungeSound.Volume = .6

local UnsheathSound = Instance.new("Sound") UnsheathSound.SoundId = "rbxasset://sounds\unsheath.wav" UnsheathSound.Parent = sword UnsheathSound.Volume = 1

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

    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

function tagHumanoid(humanoid, player) local creator_tag = Instance.new("ObjectValue") creator_tag.Value = player creator_tag.Name = "creator" creator_tag.Parent = humanoid end

function untagHumanoid(humanoid) if humanoid ~= nil then local tag = humanoid:findFirstChild("creator") if tag ~= nil then tag.Parent = nil end end end

function swordAcross() -- parry end

Tool.Enabled = true local last_attack = 0 function onActivated()

SlashSound:play()

if not Tool.Enabled then
    return
end

Tool.Enabled = false

local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
    print("Humanoid not found")
    return 
end

t = r.Stepped:wait()

--wait(.5)

Tool.Enabled = true
game:GetService("Chat"):Chat(Player.Character.Head,"Samehada, Release!")

end

function onEquipped() UnsheathSound:play() end

script.Parent.Activated:connect(onActivated) script.Parent.Equipped:connect(onEquipped)

connection = sword.Touched:connect(blow)

0
Could you please be a little more specific or provide some code? Aethex 256 — 10y
0
Here it is. Hope you can help me :/ ChristianSenpaii 29 — 10y
0
Please correctly format your post if you want people to correctly help you. MrNicNac 855 — 10y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

game is a global variable already available in the default function environment of every script. GetService and service are both analogous member functions of game.

Ad

Answer this question