简体   繁体   中英

Clone() and MoveTo() not working (Roblox)

I'm attempting to make a model move to a Vector3 position after cloning it with Clone() but neither seem to work.

local money = game.Players.LocalPlayer.Money
local player = game.Players.LocalPlayer

function Check()
if money < 3000 and money > 0 then
    local House = script.Parent.Houses.Crate:Clone()
    House:MoveTo(player.Homeloc.Value)
end

You should be indexing the value property of money

if money.Value < 3000 and money.Value > 0 then

Oh and you're missing an end , in fact you should probably revisit Lua basics, this code looks like you ripped out pieces and segments of other code or free models and then tried to fit together a logical script when it fact it doesn't make sense.

Additionally, you need to not use a LocalScript for this. Moving objects around is a server-sided operation. I would recommend using FilteringEnabled.

Also, you should check for errors from now on.

By the way, why are you defining player after money, you should define it beforehand and then index it while defining money.

When you are setting Vector3, you need to do Vector3.new(). So in this case,

House:MoveTo(Vector3.new(player.Homeloc.Value))

There are a couple things you need to fix fix with this script to get i up and running.

1st you never define "Homeloc" Homeloc must be a Vector3 value instance or a value created inside the script which also must be vector3.

2nd instead of using

MoveTo(player.Homeloc.Value)

try

MoveTo(Vector3.new(player.Homeloc.Value))

I don't know if I covered all the problems but that seems like most of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM