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

What is wrong with this script?

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

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!

2 comments

0

It worked before, but doesn't work now (meaning that the caps-sensitive most likely isn't the cause.)

0

Didn't work, but thanks anyway.

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