I didn’t understand. How do I solve this issue?
The easiest way is handle giving the player the tool yourself, imo.
I feel like we’re getting into a more complicated topic here.
For now maybe just don’t worry about the player.
But it still doesn’t work even if I remove the player. The GUI isn’t working.
Can anyone please help?
There’s multiple things going on here. First, to simulate a club-strike, you’re going to want to use ApplyImpulse. BodyVelocity applies continual force to maintain a specific velocity.
Second, body movers only work on server-owned parts. Check network ownership of the ball with golfBall:GetNetworkOwner()
if the owner is not nil, set it to nil with SetNetworkOwner(nil)
this will make sure the server is applying the body mover.
Third, make sure the part is unanchored and there is sufficient force applied to move it. For ApplyImpulse, you are going to have a normalized Vector3 direction multiplied by magnitude for the magnitude of the force. If you have different balls in the game, you will need to factor in the AssemblyMass of the part to the force calculation.
Is the ball anchored or not anchored?
It moves when I don’t use the GUI and just touch it but it doesn’t move when I press launch.
not anchored. Let me show you what it looks like without the GUI.
So this is the script:
local club = script.Parent
club.Handle.Touched:Connect(function(hit)
local bv = hit.Parent:FindFirstChild("BodyVelocity")
if bv then
game.ReplicatedStorage.DetailsEvent.OnServerEvent:Connect(function(Distance, Height, Curve)
bv.Velocity = Vector3.new(Distance, Height, Curve)
end)
end
end)
Local script
local Distance = script.Parent.Parent.Distance.Text
local Height = script.Parent.Parent.Height.Text
local Curve = script.Parent.Parent.Curve.Text
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.DetailsEvent:FireServer( Distance, Height, Curve)
end)
and GUI
I’m not sure why it doesn’t work.
It only works when I do
local bv = game.Workspace.Ball.BodyVelocity
if bv then
bv.Velocity...
end
but it doesn’t work when I do
local bv = hit.Parent:FindFirstChild("BodyVelocity")
if bv then
bv.Velocity...
end
local club = script.Parent
club.Handle.Touched:Connect(function(hit)
local bv = hit.Parent:FindFirstChild("BodyVelocity")
if bv then
game.ReplicatedStorage.DetailsEvent.OnServerEvent:Connect(function(Distance, Height, Curve)
bv.Velocity = Vector3.new(Distance, Height, Curve)
end)
end
end)
Here ^ your not listening for the server event until after the ball is touched…
What initiates the touch event in the first place?
I assume you want it to work like this:
Type in input values,
Click the launch button and…
A golf club swings? (Animation?)
When the club “touches” the ball the server launches the ball?
Do you have an animation or something that swings the club?
I don’t have any animation for the club. I am focusing on making the ball move through projectile motion[LATER DEVELOPED]. I want the player to input the values and then when the club is touching the ball, the ball the club is touching will move according to the player input when they press launch.
Yes but at what point does the club touch the ball after pressing the launch button?
You basically need to reverse your event listeners… Listen for the server event first… On button click: ServerEventFire
Then begin to listen for the club touching the ball.
OnTouch: LaunchBall
Then you have to make the club actually touch the ball, either with swing animation and proper alignment or just let the player walk around with the club until the club touches it.
It still doesn’t work. This is the code is in the golf ball. Now, when I click launch, the ball just keeps going in the y-direction regardless of other parameters.
local golfBall = script.Parent
--local Distance = game.StarterGui.ScreenGui.CalcFrame.Distance.Text
--local Height = game.StarterGui.ScreenGui.CalcFrame.Height.Text
--local Curve = game.StarterGui.ScreenGui.CalcFrame.Curve.Text
game.ReplicatedStorage.DetailsEvent.OnServerEvent:Connect(function(Distance, Height, Curve)
golfBall.Touched:Connect(function(hit)
local Club = hit.Parent
if Club.Name == "GolfClub" then
local bv = script.Parent.BodyVelocity
while wait() do
bv.Velocity = Vector3.new(Distance, Height, Curve)
end
end
end)
end)
What values are you getting for Distance and Curve? If they are much less than Height then the ball will mostly go upward.
Velocity = Direction the ball should travel in and the speed is the magnitude of that direction.
--Assuming the club/face is "looking" toward the ball
local dir = club.CFrame.LookVector + club.CFrame.UpVector --Up and forward relative to club/face
local speed = 20 studs/sec
bv.Velocity = dir * 20
This would hold the ball at 20studs/sec traveling in up/forward direction from the club part until you change the velocity again. Something like this might be done better with a vector force or impulse if those are working now.
But this still doesn’t help me find the solution for the launch button.