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

Can someone help me with my attack dog? He isn't working properly.

Asked by 9 years ago

I am making an attack dog for my game, I have the script working and all, but the dog follow me backwards when I say "follow me"? Can you take a look at this and see why the dog is following me backwards?

local admins = {"Player"}
local following = false
local attacking = false
local tracking = false
local jumping = false

script.Parent.Mouth.Touched:connect(function() if not jumping then jumping = true script.Parent.Torso.Velocity = script.Parent.Torso.Velocity + Vector3.new(0,55,0) wait(2) jumping = false end end)
local bg = Instance.new("BodyGyro", script.Parent.Torso) bg.maxTorque = Vector3.new(9e9,0,9e9) bg.cframe = CFrame.new(0, 0, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)

function ChkAdmin(str)
for i, v in pairs(admins) do if v:lower() == str:lower() then return true end end
return false
end

function GetPlr(plr, str)
local plrz = {} str = str:lower()
local sn = {1} local en = {}
for i = 1, #str do if str:sub(i,i) == "," then table.insert(sn, i+1) table.insert(en,i-1) end end
for a, plyr in pairs(game.Players:children()) do 
for x = 1, #sn do 
if (sn[x] and en[x] and str:sub(sn[x],en[x]):lower() == "me") or (sn[x] and str:sub(sn[x]):lower() == "me") then table.insert(plrz, plr)
elseif (sn[x] and en[x] and str:sub(sn[x],en[x]):lower() == "random") or (sn[x] and str:sub(sn[x]):lower() == "random") then table.insert(plrz, game.Players:children()[math.random(#game.Players:children())])
elseif (sn[x] and en[x] and plyr.Name:lower():find(str:sub(sn[x],en[x])) == 1) or (sn[x] and plyr.Name:lower():find(str:sub(sn[x])) == 1) or plyr.Name:lower():find(str) == 1 then 
table.insert(plrz, plyr) 
end 
end
end
return plrz
end

function AdminControl(plr)
plr.Chatted:connect(function(msg)
if not ChkAdmin(plr.Name) then return end
coroutine.resume(coroutine.create(function()

if msg:lower() == "stay" then 
following = false attacking = false tracking = false script.Parent.Humanoid.Jump = true script.Parent.Humanoid.Sit = false wait(.1)
script.Parent.Humanoid:MoveTo(script.Parent.Torso.Position, script.Parent.Torso)
end

if msg:lower():sub(1,7) == "follow " then
following = false attacking = false tracking = false script.Parent.Humanoid.Jump = true script.Parent.Humanoid.Sit = false
local plrz = GetPlr(plr, msg:lower():sub(8))
if plrz[1] and plrz[1].Character and plrz[1].Character:findFirstChild("Torso") and plrz[1].Character:findFirstChild("Humanoid") then
following = true
repeat wait()
script.Parent.Humanoid.WalkSpeed = plrz[1].Character.Humanoid.WalkSpeed
script.Parent.Humanoid:MoveTo((plrz[1].Character.Torso.CFrame * CFrame.new(0,0,5)).p, plrz[1].Character.Torso)
until not following
following = false
end
end

if msg:lower():sub(1,6) == "track " then
following = false attacking = false tracking = false script.Parent.Humanoid.Jump = true script.Parent.Humanoid.Sit = false
local plrz = GetPlr(plr, msg:lower():sub(7))
if plrz[1] and plrz[1].Character and plrz[1].Character:findFirstChild("Torso") and plrz[1].Character:findFirstChild("Humanoid") then
tracking = true
repeat wait()
script.Parent.Humanoid.WalkSpeed = plrz[1].Character.Humanoid.WalkSpeed + 5
script.Parent.Humanoid:MoveTo(plrz[1].Character.Torso.Position, plrz[1].Character.Torso)
until not tracking or (script.Parent.Head.Position - plrz[1].Torso.Position).magnitude <= 10
tracking = false
end
end

if msg:lower():sub(1,7) == "attack " then
following = false attacking = false tracking = false script.Parent.Humanoid.Jump = true script.Parent.Humanoid.Sit = false
local plrz = GetPlr(plr, msg:lower():sub(8))
if plrz[1] and plrz[1].Character and plrz[1].Character:findFirstChild("Torso") and plrz[1].Character:findFirstChild("Humanoid") then
attacking = true
local conn = script.Parent.Mouth.Touched:connect(function(hit) if hit.Parent == plrz[1].Character then plrz[1].Character.Humanoid.Health = 0 attacking = false conn:disconnect() end end)
repeat wait()
script.Parent.Humanoid.WalkSpeed = plrz[1].Character.Humanoid.WalkSpeed + 24
script.Parent.Humanoid:MoveTo(plrz[1].Character.Torso.Position, plrz[1].Character.Torso)
until not attacking
attacking = false
conn:disconnect()
end
end

end))
end)
end

for i, v in pairs(game.Players:children()) do AdminControl(v) end
game.Players.PlayerAdded:connect(AdminControl)
1
Not to sound rude; but, this code is horribly tabbed and VERY sloppy. So many conditionals that aren't necessary are there, and additionally, you should realize that lots of these you can turn into functions. Now the issue is that your dogs CFrame is backwards, and you need to turn him with CFrame. DigitalVeer 1473 — 9y
0
Well, how would I turn him with the Cframe? I tried everything, just can't figure it out. OfficerPapasman 2 — 9y
0
Try taking him to obedience school. It worked for my dog. LOLOLOLOLOLOLOLOLOOLOLLOLOOLLOLOLOLOLOL yumtaste 476 — 9y
0
YumTaste, my dog has over 1000 parts unioned to make it look real, Everytime I try to run the command: follow me, he follows me backwards. OfficerPapasman 2 — 9y

Answer this question