#Script help.

75 messages · Page 1 of 1 (latest)

civic thistle
#

Im trying to make a magic ball fire from a tool with chatgbt. The ball spawns in and just stays there. The problem is the ball just stays there and doesnt shoot. Id appreciate any help, thanks.

#

Heres the server side script

local tool = script.Parent
local remote = Instance.new("RemoteEvent", tool)
remote.Name = "FireBallEvent"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

-- Ensure there's a MagicBall in ReplicatedStorage
local magicBallTemplate = ReplicatedStorage:WaitForChild("MagicBall")

remote.OnServerEvent:Connect(function(player)
local character = player.Character
if not character then return end

-- Find the handle of the tool
local handle = tool:FindFirstChild("Handle")
if not handle then
    warn("Handle not found in the tool!")
    return
end

-- Get the direction the player is facing (use the HumanoidRootPart or Camera)
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end

-- Get the direction the player is facing
local direction = humanoidRootPart.CFrame.LookVector -- Direction the player is facing

-- Create the magic ball
local magicBall = magicBallTemplate:Clone()
magicBall.CFrame = handle.CFrame -- Spawn the ball at the tool's handle
magicBall.Anchored = false -- Ensure it is not anchored
magicBall.CanCollide = false -- Prevent it from colliding immediately
magicBall.Parent = workspace

-- Add BodyVelocity to make the ball move in the player's facing direction
local bodyVelocity = Instance.new("BodyVelocity", magicBall)
bodyVelocity.MaxForce = Vector3.new(1e6, 1e6, 1e6) -- Allow strong forces in all directions
bodyVelocity.Velocity = direction * 100 -- Make the ball move in the direction the player is facing
bodyVelocity.P = 3000 -- Adjust the force strength if needed

-- Debugging
print("MagicBall spawned at:", magicBall.Position)
print("MagicBall velocity set to:", bodyVelocity.Velocity)

-- Cleanup after 5 seconds
Debris:AddItem(magicBall, 5)

end)

#

this is where i have the stuff at

slender agate
#

You already have a remote event in the tool, so why are you making another one, also i tested it and the script worked?

#

all I changed was the way you parented stuff

#

dont parent the new instance like this instance.new("Part", workspace) it is from what I remember not ideal and slower

#

here is how the script looks for me

civic thistle
#

im bad at scripting and stuff so im using chatgbt ik its cringe but i gotta do it lol

slender agate
#

its alr, as long as its used for learning basics

#

altho I dont recommend it

civic thistle
#

yeah im getting the idea that its not great at writing scripts properly

slender agate
#

does the remote recive the signal on the server?

#

try a print to debug

civic thistle
#

anyways i got the ball to shoot by getting cbt to edit a working script i found in a gun in toolbox

slender agate
#

So does it work then

civic thistle
slender agate
#

o I just meant

civic thistle
slender agate
#

o nvm if it spawned

#

then no need for this

civic thistle
#

yep

slender agate
#

its this line then

#

where is the handel

civic thistle
#

its in the tool

slender agate
#

the ball is spawning in the position of the handel

#

if you want just spawn it infront of ur character?

civic thistle
#

right so im using this spawn script

#

local spawnPos = humanoidRootPart.Position
spawnPos = spawnPos + (direction * 2)

#

it spawns entirely way too far from my character still

slender agate
#

what?

#

why are you useing that

civic thistle
#

ask chat gbt lol

#

im probably going to take a proper course to learn this stuff soon

slender agate
#

if you want it to spawn infront of ur character then just take the cframe

#

of the humanoidrootpart

#

and if u want it farther infront change the z position to be more negative

#

so now the ball spawns 10 studs infront of the humanoid

civic thistle
#

changing the z position isnt making it spawn closer

restive shuttleBOT
#

studio** You are now Level 2! **studio

civic thistle
#

i tried to make it spawn further and that worked but i cant get it to spawn closer

slender agate
#

if u want it to be closer then a -1

#

or lower

civic thistle
#

i tried that

slender agate
#

?

#

do you want it in the character

civic thistle
#

preferably from the the front of the tool

#

but if that requires a rework of the whole script im good with just making it closer to my character

slender agate
#

can isee the script one more time

civic thistle
#

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

local Tool = script.Parent
local colors = {BrickColor.new("Bright blue"), BrickColor.new("Bright yellow"), BrickColor.new("Bright purple")}

-- Fire event when the player activates the tool (e.g., clicks)
Tool.Activated:Connect(function()
local player = game.Players:GetPlayerFromCharacter(Tool.Parent)
if not player or not player.Character then return end

local character = player.Character
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end

-- Create the magic ball (like the paintball missile)
local magicBall = Instance.new("Part")
magicBall.Size = Vector3.new(1, 1, 1)
magicBall.Shape = Enum.PartType.Ball
magicBall.Name = "MagicBall"
magicBall.BrickColor = colors[math.random(1, #colors)] -- Random color for the ball
magicBall.Anchored = false
magicBall.CanCollide = false
magicBall.Elasticity = 0
magicBall.Reflectance = 0
magicBall.Friction = 0.9


magicBall.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -1)  

-- Create BodyVelocity to move the ball
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e6, 1e6, 1e6) -- Allow strong forces in all directions
bodyVelocity.Velocity = humanoidRootPart.CFrame.LookVector * 1000 -- Strong force, adjust for desired speed
bodyVelocity.Parent = magicBall

-- Create a tag for the creator (player who fired the ball)
local creatorTag = Instance.new("ObjectValue")
creatorTag.Value = player
creatorTag.Name = "creator"
creatorTag.Parent = magicBall

-- Set massless to avoid gravity
magicBall.Massless = true

-- Parent the magic ball to the workspace
magicBall.Parent = workspace
#

-- Tween to make it move smoothly (optional, for smooth trajectory)
local endPosition = magicBall.Position + humanoidRootPart.CFrame.LookVector * 100 -- Adjust for distance
local tweenInfo = TweenInfo.new((endPosition - magicBall.Position).Magnitude / 100, Enum.EasingStyle.Linear)
local goal = {Position = endPosition}
local tween = TweenService:Create(magicBall, tweenInfo, goal)
tween:Play()

-- Clean up after 5 seconds
Debris:AddItem(magicBall, 5)

end)

slender agate
#

is this a new try from chatgpt.......

civic thistle
#

this is since i got the ball to actually move and after i put the magicBall.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -1) in there

slender agate
#

why are you tweening now

civic thistle
#

soooo gbt is bad at scripting lmao

#

thats what im getting from this

slender agate
#

Are you trying to learn from chatgpt or just make somethin that works

restive shuttleBOT
#

studio** You are now Level 15! **studio

civic thistle
#

mostly just make something that works

slender agate
#

So what exactly is the problem now with this version

#

it dosent even use a remote

civic thistle
#

the ball spawns too far away

slender agate
#

bruh

#

the ball isnt spawnin far, its just so fast it seems that way

#

make the speed 10

#

also no need for a tween

#

remove the tween part

civic thistle
#

oh lol ok now it is working

#

im confident i can change it to my liking from here now

#

thanks again bro