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

Why is the part not moving? used cframe and position.

Asked by 4 years ago

LOCAL SCRIPT inside of startergui

I'm making a button, when it's touched a client event fires and that part works fine but the onClientEvent function isn't working properly. I made it so when the player touches first time the ball gets inserted into workspace, the 2nd time he touches it, it makes the ball go to the position it was placed at if it moves. I used CFrame and Position to move it but they both didn't work.

01local locate = true
02 
03PE3.OnClientEvent:Connect(function()
04    local activatedPart = game.ReplicatedStorage:WaitForChild("Ball")
05 
06    print("Button activated")
07 
08    local ballCopy = activatedPart:Clone()
09 
10    if locate == true then
11        locate = false
12 
13        ballCopy.Parent = game.Workspace
14 
15    elseif locate == false then
View all 21 lines...

and no there isn't any errors in the workspace, prints? yes.

ty for help

1 answer

Log in to vote
1
Answered by
ArtBlart 533 Moderation Voter
4 years ago

Each time the even is fired, you're cloning a new ball. Just make sure you only clone the ball once.

Ideally, you'd want to move the cloning outside the event entirely like so:

1local locate = true
2local ballCopy = game.ReplicatedStorage:WaitForChild("Ball"):Clone()
3 
4PE3.OnClientEvent:Connect(function()
5    --...
6end
0
Thanks for catching that! ZombieApocalypz3 35 — 4y
Ad

Answer this question