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

What is wrong with this script?

Asked by
RedCombee 585 Moderation Voter
10 years ago
local t = script.Parent.Trainer.Value
local g = Instance.new("BodyGyro",script.Parent)
while wait() do
    local list = game.Workspace:GetChildren()
    for i = 1, #list do
        local n = list[i]
        if n.Name == t then
            local torso = n:FindFirstChild("Torso")
            script.Parent:WaitForChild("Pokemon"):MoveTo(torso.Position - (torso.CFrame.lookVector * 3),torso)
            g.cframe = CFrame.new(script.Parent.Torso.Position,torso.Position)
        end
    end
end

This script causes my Pokemon to walk to the trainer that owns it. But for some reason, it doesn't work anymore. I found this out shortly after a roblox update and I want to fix it. Now when it runs, it seems to only move to it's set position once, and then it stops following completely.

NOTE: No errors have occurred.

1 answer

Log in to vote
0
Answered by 10 years ago

Revised code:

local t = script.Parent.Trainer.Value
local g = Instance.new("BodyGyro", script.Parent)
while wait() do
    local list = game.Workspace:GetChildren()
    for i = 1, #list do
        local n = list[i]
        if n.Name == t then
            local torso = n:FindFirstChild("Torso")
            script.Parent:WaitForChild("Pokemon"):MoveTo(torso.Position - (torso.CFrame.lookVector * 3),torso)
            g.CFrame = CFrame.new(script.Parent.Torso.Position, torso.Position)
        end
    end
end

I think the main problem is here (line 10): g.cframe = CFrame.new(script.Parent.Torso.Position,torso.Position).
Case-sensitivity is very important in Lua. I changed that to: g.CFrame = CFrame.new(script.Parent.Torso.Position, torso.Position). I also added spaces between the commas. This isn't required, but it helps me.

Replace your code with the code I provided above, and see if it works.

Hope this helped!

0
It worked before, but doesn't work now (meaning that the caps-sensitive most likely isn't the cause.) RedCombee 585 — 10y
0
Didn't work, but thanks anyway. RedCombee 585 — 10y
Ad

Answer this question