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

Part doesnt move when i use local script. whats the problem?

Asked by 6 years ago

So i was trying to move a part in workspace using a local script so it doesnt replicate from the client to the server inside the part there is a clickdetector so when i click it it moves the script i used found here (https://developer.roblox.com/articles/Sliding-Parts) Heres the script

local Part = workspace.Part -- this is the Part we will move
local newPos = Part.Position + Vector3.new(0,5,0) -- the position the Part will go to
local Time = 10 -- the time that the script will take to move the part
local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
local Debounce = false

local Diff = newPos - Part.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, newPos).lookVector

function MovePart() -- function to move the Part
    if Debounce then return end -- end the function if debounce is true
    Debounce = true -- make Debounce true so the function can't run
    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * Increment)
        wait( (Time/Mag) * Increment )
    end
    Debounce = false -- set Debounce to false so the function can run again
end

workspace. Part. ClickDetector. MouseClick(MovePart) 

This works well in server sided script but it doesnt work in local scripts idk why any suggestions?

0
its not supposed to, especially when FE is on, the answer is RemoteEvents/Functions https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events GoldAngelInDisguise 297 — 6y
0
Thanks for your reply really helpful but i want the part to be invisible to other players Zheercombater1 -1 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

This is actually rather simple to explain. Local scripts should only be used when doing something that requires the client to be used, such as accessing the player or accessing and changing the properties of a GUI. Part movement by CFrame should be done server side because CFrame will not work on the client, as the client is unable to edit CFrame. Same goes for calculating with magnitude.

Ad

Answer this question