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

Why isnt this replicated storage script not working?

Asked by
TrollD3 105
9 years ago

So Im trying to make a txt button so that when clicked, it clones the weapon and brings out and positions it to a certain location. The button is an arrow key( >). Why wouldn't this work? I want it so that every time its clicked, ****a different weapon shows up at the position ( with the previous deleted)****.( Im trying to do a Phantom forces like custom class.) Its says Moveto is not a valid member of tool in output. For better idea of what im talking about : http://prntscr.com/70vf5h

script :

function click()
    local weapon = game.ReplicatedStorage:FindFirstChild("KF5"):clone()
    weapon:MoveTo(Vector3.new(42.5,628.8,48.5))
end
script.Parent.MouseButton1Click:connect(click)


function click()
    local weapon = game.ReplicatedStorage:FindFirstChild("ARX-160"):clone()
weapon:MoveTo(Vector3.new(42.5,628.8,48.5))
end
script.Parent.MouseButton1Click:connect(click)

1 answer

Log in to vote
0
Answered by 9 years ago

MoveTo() works only for models. So, instead you can move this tool in two different ways, with CFrame, or Position. Due to the tool probably being anchored, you'll want to use Position. All of the code appears to be fine, execept line 12 may confuse the script due to two functions of the same name existing! Also, they both are called at the same event, you should change the function name and event for 1! Something like that as a fix, I do not know what would happen if you did not change what I mention. Anyway, here is your script for positioning the tool:

function click()
    local weapon = game.ReplicatedStorage:FindFirstChild("KF5"):clone()
    weapon.Part.Position = Vector3.new(42.5,628.8,48.5)
end
script.Parent.MouseButton1Click:connect(click)


function click()
    local weapon = game.ReplicatedStorage:FindFirstChild("ARX-160"):clone()
weapon.Part.Position = Vector3.new(42.5,628.8,48.5)
end
script.Parent.MouseButton1Click:connect(click)

I am assuming "Part" is the correct name of the part inside tool, that may need to be fixed if I am wrong.

Now, I am not sure if there is actually more than 1 part inside or not, so position or cframe will cause problems. Then, you will want to model the parts together inside of tool for MoveTo() to work. (I don't believe models will effect anything unless your scripts inside will have a hierarchy error) In this case, just do what you did but instead of the tool, go further in and to the Model!

function click()
    local weapon = game.ReplicatedStorage:FindFirstChild("KF5"):clone()
    weapon.Model:MoveTo(Vector3.new(42.5,628.8,48.5))
end
script.Parent.MouseButton1Click:connect(click)


function click()
    local weapon = game.ReplicatedStorage:FindFirstChild("ARX-160"):clone()
weapon.Model:MoveTo(Vector3.new(42.5,628.8,48.5))
end
script.Parent.MouseButton1Click:connect(click)

If this positions strangely, find the middle part for more precise movement and set it as primary part. How? Like this:

game.Workspace.Model.PrimaryPart = MiddlePart -- this is a name of a part in "Model"

I hope this helped! More information on your part would have also helped, but I did what i could with what I had.

0
It doesnt show anymore errors. But it still doesnt work. TrollD3 105 — 9y
0
and its not a model. Its a tool with parts in it. TrollD3 105 — 9y
Ad

Answer this question