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

Made a ball launcher, how do I make the ball shoot where the player is looking?

Asked by 6 years ago
Edited 6 years ago
01local handle = script.Parent.Handle
02local debounce  = false
03 
04script.Parent.Activated:Connect(function()
05    if not debounce then
06        debounce = true
07 
08        local cloned = game.ServerStorage.bomb:Clone()
09        cloned.Parent = workspace
10        cloned.CFrame = handle.CFrame*CFrame.new(0, 1, 0)
11        cloned.Velocity = Vector3.new(0, math.random(50, 100), 0)
12 
13        wait(5)
14        debounce = false
15    end
16end)

The above code is supposed to create a clone of a sphere named "bomb" in ServerStorage, set the Parent of the clone to game.Workspace, match its CFrame to the tool's Handle CFrame (plus 1 point up on the y axis). It also gives the clone a velocity of 0 for the x axis, a random number between 50 and 100 for the y axis, and 0 for the z axis. The thing is, it obviously shoots up, and that's it. I want this block to shoot out in the direction that the player holding the tool is looking in. How could I do this?

0
take the front vector of their torso and multiply it Fad99 286 — 6y
0
I'll see if I can User#28017 0 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

One problem that I have seen is that a client is trying to access the server storage. Instead, use replicated storage. Don't forget that the names of objects are case sensitive. Secondly, using a bodyvelocity allows a constant force to be applied to a specific part. I have fixed these problems in the code below.

01local handle = script.Parent.Handle
02local debounce  = false
03local replicatedStorage = game:GetService("ReplicatedStorage")
04local bomb = replicatedStorage:WaitForChild("Bomb")
05local maxSpeed = 25 -- Not studs per second
06local waitTime = 5
07 
08script.Parent.Activated:Connect(function()
09    if not debounce then
10        debounce = true
11 
12        local cloned = bomb:Clone()
13        cloned.Parent = workspace
14        cloned.CFrame = handle.CFrame*CFrame.new(0, 1, 0)
15 
View all 25 lines...
0
I understand the code other than the details about the instance of a BodyVeloctiy. The code ran when the tool was activated, but it did not shoot the ball where the player is looking at. It does shoot it forward a little bit, but mainly it flies up into the sky. User#28017 0 — 6y
0
I check the "Bomb" in ReplicatedStorage, and the bomb didn't have a script modifying its velocity. User#28017 0 — 6y
0
The tool modfiys the object. I tried this script with a sphere in replicatedstorage. SaltyIceberg 81 — 6y
Ad

Answer this question