I found a wand on the toolbox, made by a User called Davy (don't know his full name). Currently, I'm reworking the entire tool, making it much more modern as well as adding sound and other cool effects. I'm doing this since it will be the main tool for my group.
Here's the problem. I've realised that the spells/projectiles don't stop once it hits the wall, but rather continues. This means fights will be unfair since you can practically scope people, and not be able to hide behind cover. Is there any way to fix this problem? I've tried finding tutorials, but they're for gun scripts and not this type of script.
TL;DR: Trying to find a way to stop the spell shooting through walls. Can you help me?
The script is here:
print("Loading Davy's Wand...")
local wand = script.Parent
local stick = wand.Handle
local inc = script.Name
local owner, connect
function SpellAffect(hit,spell)
if (not hit.CanCollide) and (hit.Parent:findFirstChild("Humanoid") == nil) then return end
local hum = hit.Parent:findFirstChild("Humanoid")
if (hum) then
--Put stuff here concerning aperson and his life.
else
--Put stuff here affecting non-players.
end
--Put stuff here affecting all bricks.
if hit.Name == "Handle" then
if hit.Parent.Parent == game.Workspace then
local i = Instance.new("BodyPosition")
i.position = wand.Parent.Torso.Position
i.Parent = hit
game.Debris:AddItem(i,3)
spell:Remove()
end end end
function Setup()
for i,p in pairs(game.Players:children()) do
if (p.Character == wand.Parent) then
print("Found owner of wand!")
if (connect ~= nil) then connect:disconnect() end
connect = p.Chatted:connect(PlayerTalked)
owner = p
end
end
end
enabled = true
function PlayerTalked(words)
if not enabled then
return
end
print("Someone talked!")
if (string.find(words:lower(), inc:lower()) ~= nil) and (wand.Parent == owner.Character) then
print("Casting the spell ''" ..inc.. "''")
CastSpell()
enabled = false
wait (4)
enabled = true
end
end
function CastSpell()
if script.Parent.SpellCount.Value >= 3 then return end
script.Parent.SpellCount.Value = script.Parent.SpellCount.Value + 1
for i = 1, script.Parent.SpellCount.Value do
wand.Activated:wait()
end
script.Parent.SpellCount.Value = script.Parent.SpellCount.Value - 1
local p = Instance.new("Part")
p.formFactor = "Symmetric"
p.Shape = "Ball"
p.Size = Vector3.new(1,1,1)
p.TopSurface = "Smooth"
p.BottomSurface = "Smooth"
p.Transparency = 1
p.BrickColor = script.SpellColor.Value
local sparx = Instance.new("Sparkles")
sparx.SparkleColor = script.SparkColor.Value
sparx.Enabled = script.HasSparkles.Value
sparx.Parent = p
coroutine.resume(coroutine.create(function()
------------------------
local SpellEFX = script.Parent.SpellEffects.White:Clone()
SpellEFX.Parent = p
SpellEFX.Enabled = true
------------------------
local LightEFX = script.Parent.LightEffects.White:Clone()
LightEFX.Parent = p
LightEFX.Enabled = true
------------------------
wait(5)
p:Remove()
end))
local bv = Instance.new("BodyVelocity")
p.Parent = workspace
p.Name = "MagicSpell"
p.CFrame = stick.CFrame * CFrame.new(0,1.5,0)
bv.Parent = p
bv.velocity = ((owner.Character.Humanoid.TargetPoint - p.Position).unit) * 200
p.Touched:connect(function(part)
SpellAffect(part,p)
end)
end
wand.Equipped:connect(Setup)
Thanks for any help.

3 comments
Have you tried raycasting?
Yeah, but I don't know how I would place the ray casting into the script. I've tried placing it into there myself, yet it the entire spell just doesn't work when I do that.
Has anybody else got a solution?