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

What is wrong with my gui button that is supposed to move your character a distance away?

Asked by 6 years ago

In the following script, you press a gui button and it would move your character, it doesn't seem to work so I tried multiply body parts, here are some examples.

script.Parent.MouseButton1Click:connect(function(idk)
    script.Parent.Parent.Parent.Parent.Character.Head.Cframe = CFrame.new(script.Parent.Parent.Parent.Parent.Character.Head.Position + 0, 100, 0)
end)
script.Parent.MouseButton1Click:connect(function(idk)
    script.Parent.Parent.Parent.Parent.Character.UpperTorso.Cframe = CFrame.new(script.Parent.Parent.Parent.Parent.Character.UpperTorso.Cframe + 0, 100, 0)
end)

and here is the script I used to test if this would somehow work in the first place

script.Parent.MouseButton1Click:connect(function(idk)
    script.Parent.Value.Value = script.Parent.Parent.Parent.Parent.Name
    print ("Hi "..script.Parent.Value.Value.."!")
end)
0
First off, when you are adding positions, you have to add them as a vector3 value. In your first block of code, replace "0, 100, 0" with Vector3.new(0, 100, 0) make sense? Also, did the script you used to check and see if it works, actually work? Your_Momdotcom 91 — 6y
0
yes KatsuneSniper 31 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

When using CFrame, it is case-sensitive. You put Cframe, in which it should've been CFrame.

Secondly, you're setting the head's CFrame, CFrame isn't a property of the part, it is a property used to change the part as a data value. The Position is the real thing you want to change here.

script.Parent.MouseButton1Click:connect(function(idk) -- first script
    script.Parent.Parent.Parent.Parent.Character.Head.Position
=CFrame.new(script.Parent.Parent.Parent.Parent.Character.Head.Position + 0, 100, 0)
end)

By the way, I recommend using CFrame.new(Vector3.new()) instead also but both still do the same, it's just Vector3 is a proper way of handling xyz coordinates in my opinion.

script.Parent.MouseButton1Click:connect(function(idk) -- first script again
    script.Parent.Parent.Parent.Parent.Character.Head.Position = CFrame.new(Vector3.new(script.Parent.Parent.Parent.Parent.Character.Head.Position + 0, 100, 0))
end)
script.Parent.MouseButton1Click:connect(function(idk) -- second script
    script.Parent.Parent.Parent.Parent.Character.UpperTorso.Position = CFrame.new(Vector3.new(script.Parent.Parent.Parent.Parent.Character.UpperTorso.Position + 0, 100, 0))
end)

If it doesn't work then try these other two scripts:

script.Parent.MouseButton1Click:connect(function(idk) -- first script
    script.Parent.Parent.Parent.Parent.Character.Head.Position = CFrame.new(Vector3.new(script.Parent.Parent.Parent.Parent.Character.Head.Position))
    script.Parent.Parent.Parent.Parent.Character.UpperTorso.Position = script.Parent.Parent.Parent.Parent.Character.UpperTorso.Position + Vector3.new(0, 100, 0)
end)
script.Parent.MouseButton1Click:connect(function(idk) -- second script
    script.Parent.Parent.Parent.Parent.Character.UpperTorso.CFrame = CFrame.new(Vector3.new(script.Parent.Parent.Parent.Parent.Character.UpperTorso.CFrame))
    script.Parent.Parent.Parent.Parent.Character.UpperTorso.Position = script.Parent.Parent.Parent.Parent.Character.UpperTorso.Position + Vector3.new(0, 100, 0)
end)

By the way, you don't have to fill in 'idk', instead you could leave it blank, but this isn't important, just saying.

0
Thanks, even though I solved the problem, I'll accept your answer KatsuneSniper 31 — 6y
0
Your most welcome! User#18043 95 — 6y
Ad

Answer this question