Have you tried doing other.Parent.Name instead of other.Name? If not, give it a try.
Also, make sure to add print functions, as print debugging helps greatly!
Yeah, tried that but no luck there.
Itâs odd because I havenât really changed much of the original scripts from the guide.
I remember there being a few syntax errors with the guide, however I was able to fix those.
I thought it could be an issue with the projectile being CanCollide = false but it turns out that had no effect either.
I am willing to try out region3 but I have no idea on how to go about that in this instance.
Would this be kind of what you are looking for?
Gif:
Explanation:
All i did was rework some of the scripting although i made the projectile pretty much 100% ServerSide which i would not recommend because although it does work, sometimes it may cause slight projectile delay.
I changed the launch from a remote function to event and handled it all through an event. I also scripted it so it detects if its another player/NPC. If you want to do something else with it that shouldnât be too hard of a change. As long as you know what youâre doing its pretty self explanatory. You should be able to easily edit the code to fit your game by putting this into the blaster handler in place of the NPC check thing i made.
-- Hit an enemy or wall, destroy the projectile and tell the server to destroy its copy
projectile:Destroy()
destroyProjectile:FireServer(serverProjectile)
-- Hit an enemy, destroy it and tell the server to destroy it as well
if other.Name == "EnemyBall" then
destroyEnemy:FireServer(other)
other:Destroy()
end
end
In Blaster Handler:
Code
local launchProjectile = ReplicatedStorage:WaitForChild("LaunchProjectile")
local projectileTemplate = ReplicatedStorage:WaitForChild("Projectile")
local PROJECTILE_SPEED = 40
-- How often a projectile can be made on mouse clicks (in seconds)
local LAUNCH_COOLDOWN = .05
-- How far away the projectile is created from the front of the player
local PROJECTILE_OFFSET = 5
launchProjectile.OnServerEvent:Connect(function(player, Type)
if Type == "Shoot" then -- Just used a string as an example to show that you are "Shooting"
print("Firing Projectile")
local projectile = projectileTemplate:Clone()
local playerCFrame = player.Character.PrimaryPart.CFrame
local direction = playerCFrame.LookVector
projectile.Position = playerCFrame.Position + direction * PROJECTILE_OFFSET
projectile.Velocity = direction * PROJECTILE_SPEED
local mass = projectile:GetMass()
projectile.BodyForce.Force = Vector3.new(0, 1, 0) * mass * game.Workspace.Gravity
projectile.Parent = game.Workspace
projectile.Touched:Connect(function(hit)
if hit.Parent.Name == player.Name or hit.Name == projectileTemplate.Name then
hit = nil
else
projectile:Destroy() -- Destroys the projectile if it touches anything (Except the Player shooting it or other Projectiles)
local hum = hit.Parent
local char = hum:FindFirstChild("Humanoid")
if hum and char then -- Checks if the target is an enemy npc/player
char:TakeDamage(10)
end
end
end)
game:GetService("Debris"):AddItem(projectile, 8.5) -- Getting rid of the projectile after 8.5 seconds
end
end)
In Blaster Launcher:
Code
-- This script handles blaster events on the client-side of the game
-- How fast the projectile moves
local PROJECTILE_SPEED = 40
-- How often a projectile can be made on mouse clicks (in seconds)
local LAUNCH_COOLDOWN = .05
-- How far away the projectile is created from the front of the player
local PROJECTILE_OFFSET = 1
-- Variables for Roblox services
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Variables for RemoteEvents and Functions (see the BlasterHandler Script)
local LaunchProjectile = ReplicatedStorage:WaitForChild("LaunchProjectile")
local destroyProjectile = ReplicatedStorage:WaitForChild("DestroyProjectile")
local destroyEnemy = ReplicatedStorage:WaitForChild("DestroyEnemy")
local ping = ReplicatedStorage:WaitForChild("Ping")
-- Variable to store the basic projectile object
local projectileTemplate = ReplicatedStorage:WaitForChild("Projectile")
-- Variable for the player object
local player = Players.LocalPlayer
local canLaunch = true
-- Fires when the player clicks the mouse
local function onLaunch()
-- Only launch if the player's character exists and the blaster isn't on cooldown
if player.Character and canLaunch then
-- Prevents the player from launching again until the cooldown is done
canLaunch = false
spawn(function()
wait(LAUNCH_COOLDOWN)
canLaunch = true
end)
LaunchProjectile:FireServer("Shoot")
-- Tell the server to create a new projectile and send it back to us
end
end
-- Connect a function to the ping RemoteFunction. This can be empty because all
-- the server needs to hear is a response
ping.OnClientInvoke = function() end
ContextActionService:BindAction("Launch", onLaunch, false, Enum.UserInputType.MouseButton1)
Extra Notes:
Notes
I would recommend adding the projectile to Debris after a while, that way the game doesnât get flooded with Projectiles in the workspace. (I.E:
game:GetService("Debris"):AddItem(Projectile, 15)
Lua Downloads:
BlasterHandler.lua (3.2 KB)
BlasterLauncher.lua (1.8 KB)
- Make sure this is a local script in StarterPlayerScripts
BlasterRemotes.lua (1.1 KB)
Projectile.rbxm (2.6 KB)
- The Projectile i made for this test
I Hope this helps!