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

Want to use BodyPosition a part into a random spot when a button is clicked, how to fix my script?

Asked by 4 years ago

Basically, all the random coordinates are the places it can go to. When I click the TextButton though, the BodyPosition won't change and it doesn't move towards my destination. This is a script inside TextButton, which is in a ScreenGui, which is in StarterGui.

flickball = workspace.ball.BodyPosition.Position

if script.Parent.MouseButton1Click:Connect(function()

end)
    then
balldestination = math Random (1,9)
if balldestination == 1 then
    flickball = Vector3.new(-364.459, 12.823, -380.102)
end
if balldestination == 2 then
    flickball = Vector3.new(-364.459, 13.118, -384.488)
end
if balldestination == 3 then
    flickball = Vector3.new(-364.459, 13.118, -388.348)
end
if balldestination == 4 then
    flickball = Vector3.new(-364.459, 13.118, -393.201)
end
if balldestination == 5 then
    flickball = Vector3.new(-364.459, 12.823, -397.441)
end
if balldestination == 6 then
    flickball = Vector3.new(-364.459, 5.271, -380.281)
end
if balldestination == 7 then
    flickball = Vector3.new(-364.459, 5.395, -383.592)
end
if balldestination == 8 then
    flickball = Vector3.new(-364.459, 5.395, -393.201)
end
if balldestination == 9 then
    flickball = Vector3.new(-364.459, 5.271, -397.441)
end
end

1 answer

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
4 years ago

You don't need if statement The function will run itself

Here is function

script.Parent.MouseButton1Click:Connect(function()

end)

And you need RemoteEvent to change Value.

Insert RemoteEvent and normal script in local script.

Use FireServer and OnServerEvent.

Local Script

script.Parent.MouseButton1Click:Connect(function()
  script.RemoteEvent:FireServer(game.Players.LocalPlayer.Character)
end)

Normal Script

local flickball = workspace.ball.BodyPosition


script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,char)
balldestination = math Random (1,9)
if balldestination == 1 then
    flickball.Position = Vector3.new(-364.459, 12.823, -380.102)
end
if balldestination == 2 then
    flickball.Position = Vector3.new(-364.459, 13.118, -384.488)
end
if balldestination == 3 then
    flickball.Position = Vector3.new(-364.459, 13.118, -388.348)
end
if balldestination == 4 then
    flickball.Position = Vector3.new(-364.459, 13.118, -393.201)
end
if balldestination == 5 then
    flickball.Position = Vector3.new(-364.459, 12.823, -397.441)
end
if balldestination == 6 then
    flickball.Position = Vector3.new(-364.459, 5.271, -380.281)
end
if balldestination == 7 then
    flickball.Position = Vector3.new(-364.459, 5.395, -383.592)
end
if balldestination == 8 then
    flickball.Position = Vector3.new(-364.459, 5.395, -393.201)
end
if balldestination == 9 then
    flickball.Position = Vector3.new(-364.459, 5.271, -397.441)
end
end)

RemoteEvent

Ad

Answer this question