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

Why is it when I try to do BodyPosition.position = Vector3.new(whatever goes here) it isnt working?

Asked by
mnaj22 44
7 years ago

Well I am not getting any errors. When the part spawns the BodyPosition goes to 0, 0, 0 for some reason. The topos is defined, I have already tried printing it. The BodyPosition is also working because if I were to move the part upwards it would glide right back down. Any solutions? Around lines 13-17 is where I think the problem is.

local serverstorage = game:GetService("ServerStorage")

function clone(player, part, position, topos)
    local magics = serverstorage.magicstuff
    local thing = magics:FindFirstChild(part)
    local magics2 = magics:GetChildren()
    for _, stuff in pairs(magics2) do
        if stuff.Name == part then
            thing = stuff
        end
    end
    if thing ~= nil then
        local parts = thing:Clone()
        parts.Parent = game.Workspace
        parts.Position = Vector3.new(position)
        local bp = parts.BodyPosition
        bp.position = Vector3.new(topos)
    else
        print 'A part is not in magicstuff'
    end
end

script.Parent.OnServerEvent:connect(clone)

0
Sorry for the long title, it kept telling me to be specific. mnaj22 44 — 7y
0
The problem likely lies with the "topos" parameter in that it is not supplied correctly. cabbler 1942 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

Case Sensitive Properties!!!

Actually, the property names are CASE SENSITIVE, so in line 17, it should be Position instead of position.

Let me fix your script:

local serverstorage = game:GetService("ServerStorage")

function clone(player, part, position, topos)
    local magics = serverstorage.magicstuff
    local thing = magics:FindFirstChild(part)
    local magics2 = magics:GetChildren()
    for _, stuff in pairs(magics2) do
        if stuff.Name == part then
            thing = stuff
        end
    end
    if thing ~= nil then
        local parts = thing:Clone()
        parts.Parent = game.Workspace
        parts.Position = Vector3.new(position)
        local bp = parts.BodyPosition
        bp.Position = Vector3.new(topos) -- HERE!!!!
    else
        print 'A part is not in magicstuff'
    end
end

script.Parent.OnServerEvent:Connect(clone) -- Also, use :Connect() instead of :connect() now!

If you have any questions, please leave a comment below! Thanks and I hope this will help!

0
Nice eye, but it is still not working, the part still goes to 0, 0, 0 mnaj22 44 — 7y
0
I see, then you should show me the script where you called the Event as well! This is because the Event fires with the position argument, and I can't see where you passed it. starlebVerse 685 — 7y
0
Just posted it (as a answer) mnaj22 44 — 7y
0
Omg, let me tell you how I just fixed it. At line 17 I removed Vector3.new and then it worked. mnaj22 44 — 7y
View all comments (2 more)
0
You helped so i'll accept mnaj22 44 — 7y
0
Wow glad you can figure it out :) Nicely done! starlebVerse 685 — 7y
Ad
Log in to vote
0
Answered by
mnaj22 44
7 years ago

Couldn't figure out how to edit my question, but this is the other script.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function equiped()
    local plrgui = player.PlayerGui
    plrgui.SpellGui.SpellFrame.Visible = true
end

function unequiped()
    local plrgui = player.PlayerGui
    plrgui:WaitForChild("SpellGui").SpellFrame.Visible = false
end

function isequip()
    if script.Parent.Parent.Parent.ClassName == "Model" then
        return true
    else
        return false
    end
end

function change()
    if script.Parent.Parent.Parent.ClassName == "Model" then
        equiped()
    else
        unequiped()
    end
end

script.Parent.Parent.Changed:connect(change)

function mouseclick()
    local plrgui = player.PlayerGui
    local hit = mouse.Hit
    if isequip() == true then
        if plrgui.SpellGui.spelltype.Value == "Fire" then
            local magic = script.Parent.Parent.Shoot
            --magic.Position = Vector3.new(script.Parent.Parent.Shoot.Position)
            --local bg = script.BodyGyro:Clone()
            --local bp = script.BodyPosition:Clone()
            local topos = mouse.Hit.p
            --bg.Parent = magic
            --bp.Parent = magic
            --bp.Position = Vector3.new(hit.p)
            game.Workspace.Events.Cloning:FireServer("Shootf", script.Parent.Parent.Shoot.Position, topos)
        end
    end
end

mouse.Button1Down:connect(mouseclick)

Answer this question