#Script help.
75 messages · Page 1 of 1 (latest)
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
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
im bad at scripting and stuff so im using chatgbt ik its cringe but i gotta do it lol
yeah im getting the idea that its not great at writing scripts properly
anyways i got the ball to shoot by getting cbt to edit a working script i found in a gun in toolbox
So does it work then
i wouldnt know how to call that from a print script i have little to no scripting knowledge im sorry
o I just meant
yes but the ball is spawning too far from my character so im trying to fix that
yep
its in the tool
the ball is spawning in the position of the handel
if you want just spawn it infront of ur character?
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
ask chat gbt lol
im probably going to take a proper course to learn this stuff soon
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
changing the z position isnt making it spawn closer
** You are now Level 2! **
i tried to make it spawn further and that worked but i cant get it to spawn closer
i tried that
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
can isee the script one more time
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)
is this a new try from chatgpt.......
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
why are you tweening now
Are you trying to learn from chatgpt or just make somethin that works
** You are now Level 15! **
mostly just make something that works
the ball spawns too far away