it is a client script located in starter gui, its for a golf ball when u click the golf ball the golf ball should get launched but it does not, (the camera is locked into a part’s position btw)
script:
local ball = workspace:WaitForChild("GolfBall")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local target = mouse.Target
mouse.Button1Down:Connect(function()
if target.Position == ball.Position then
local force = mouse.Hit.LookVector * 1000
ball:ApplyImpulse(force)
end
end)
you need to get the mouse target whenever they click
local ball = workspace:WaitForChild("GolfBall")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
if mouse.Target == ball then
local force = mouse.Hit.LookVector * 1000
ball:ApplyImpulse(force)
end
end)
also im not sure if that force calculation will work correctly, try this instead
local force = (mouse.Hit.Position-workspace.CurrentCamera.Position).unit*Vector3.new(1,0,1)*1000
Try this and it’s should be worked serverside ball instead clientside won’t work unless it was clientsided ball from ReplicatedStorage Parent to workspace. Here you only need add more 2 stuff ( Script and RemoteEvent )
If ball is serversided
Client
local ball =workspace:WaitForChild("GolfBall")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
if mouse.Target==ball then
game.ReplicatedStorage.RemoteEvent:FireServer(mouse.Hit.LookVector*5)
end
end)
Serverside
local ball=workspace.GolfBall
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,Stuff)
ball.Velocity=ball.Velocity+Stuff
end)
But if normally if ball clientsided only
local ball =workspace:WaitForChild("GolfBall")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
if mouse.Target==ball then
ball.Velocity=ball.Velocity+mouse.Hit.LookVector*5
end
end)
they don’t work, i am trying to make if u drag the ball to the sky it goes the way he launched it, and if the ball is clicked the ball goes slowly, and jsyk that the player can’t move the camera cuz it is locked into a part’s position
How about this? feel free to check ( it’s totally clientside and i added collisiongroup for prevent player push golf ball )
I can tell you still can configure some stuff
Golf ball with BodyAngularVelocity : You can modify MaxTorque for resist ball rolling
Velocitymax configuration it’s in ReplicatedFirst > LocalScript ( normal i set 200 )
I forget Fix player collisiongroup
its should be
game.Player.PlayedAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(c)
task.wait(1) – still sure sometime need take more time to load character
for i,v in pairs(c:getDeceseant)do
if v:IsA’BasePart"then
v.CollisionGroup=‘plr’
end