Want to stay connected to the Scripting Helpers community and get real-time help? Join the Scripting Helpers Discord Server!
Ad
Log in to vote
0

Possiblity Of Moving A Model?

Asked by 8 days ago
Edited 8 days ago

I have a script which clones and then teleports a Model inside ServerStorage to the Mouse's Location, I need a way to move the Model slowly up, and then down, i tried anything possible, but when the model spawns, its location is changed, like if the Model is on a BasePlate, its position is changed, which means it doesn't spawn at the location of mouse.

Script [ Created By A Nice Fellow ]

local event = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
event.Name = "Ready2"
local Check = game.Players.LocalPlayer.Character.Head:WaitForChild("Check")

local function SetTransparency(p, t)
    for i,v in pairs(p:GetChildren()) do
        if v:IsA"BasePart" then
            v.Transparency = t
        end
    end
end

event.OnServerEvent:Connect(function(plr, pos)
    local Bone2 = game.ServerStorage.Bone2:Clone()
    local Transparent = script.Parent.Transparent.Value
    Bone2:SetPrimaryPartCFrame(pos)
    Bone2.Parent = workspace 
    if Check.Value == true then
    SetTransparency(Bone2.Bonez.MoreBonez, 0)

    elseif Check.Value == false or Check == nil then

    wait(Transparent)
    SetTransparency(Bone2.Bonez, 0)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.1)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.2)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.3)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.4)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.5)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.6)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.7)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.8)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 0.9)
    wait(0.04)
    SetTransparency(Bone2.Bonez, 1)
    wait(0.01)
    Bone2:Destroy()
    Bone2:Destroy()
    Bone2:Remove()

end
end
end

[ Note2 : There is actually another script which fires the RemoteEvent, so.. no need to check the other errors? ]

1 answer

Log in to vote
0
Answered by
mattscy 2232
8 days ago
Edited 8 days ago

If you wanted the model to move to the mouse's position, you can use SetPrimaryPartCFrame if you want to specify rotation, or MoveTo if the orientation doesn't matter. If you want the model to slowly rise and fall on top of this, I would use a separate loop to keep track of the height.

local Mouse = game.Players.LocalPlayer:GetMouse()
local CurrentModel
local Offset = 1

local function SelectModel(Model)
    CurrentModel = Model
    Model.PrimaryPart = Model.PrimaryPart or Model:FindFirstChildWhichIsA("BasePart",true) --make sure model has a primary part
    Mouse.TargetFilter = Model --make sure mouse doesn't interact with model
end

SelectModel(ClonedModelHere) --when a new model is selected

Mouse.Move:Connect(function()
    if CurrentModel then
        local Pos = Mouse.Hit.p
        CurrentModel:MoveTo(Vector3.new(Pos.X,Pos.Y + Offset,Pos.Z)) --add floating offset to Y position
    end
end)

--control floating offset:
while true do
    for i = -1,1,0.1 do
        Offset = i
        wait()
    end
    for i = 1,-1,-0.1 do
        Offset = i
        wait()
    end
end

Hopefully this outline helps!

0
I have a little problem, where should i place these lines at? i mean like, inside the Model which gets teleported or inside the Script that i pasted? AIphanium 24 — 8d
0
And another problem, i used it inside the Pasted Script, but the Model disappeared... AIphanium 24 — 8d
0
You can't exactly just paste this script, it requires some adaptation and is just an outline. If you don't know how to script yourself, I can't really help sorry. But it should go in a LocalScript in somewhere like StarterGui for mouse interaction to work. mattscy 2232 — 8d
0
You are right, i cannot really script, i'm barely a newbie, but i have enough knowledge to detect what Each Line does. AIphanium 24 — 8d
Ad

Answer this question