Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why my projectile wont damage ontouch?

hello. i have been making a projectile shooting mechanism. works preety fine! localscript:

local sound = script.fire local tweenservice = game:GetService("TweenService") local plr = game.Players.LocalPlayer

local tear1 = game.ReplicatedStorage.Player1tear local UIS = game:GetService("UserInputService") UIS.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.E then print("Working") sound:Play() local clonetear = tear1:Clone() clonetear.Parent = game.Workspace clonetear.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5 tweenservice:Create(clonetear,TweenInfo.new(1,0,0),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 40,Transparency = 1},Enum.EasingStyle.Quint,Enum.EasingDirection.Out):Play() end end)

keep in mind, i keep the projectile in replicatedstorage. now i wanna make the projectiles actually damage on touch. for some reason, this doesnt work. any help?

2 answers

(This code allow the ball to get deleted after hitting players or any parts)

script.parent.Touched:Connect(function(hit)
	if hit.parent:FindFirstChild("Humanoid") then
		hit.Parent:FindFirstChild("Humanoid"):TakeDamage() -- put the number of health u want to make player lose in this bracket 
		wait()
game.Debris:AddItem(0,script.Parent)
end
end
else
game.Debris:AddItem(0,script.Parent)
	end 
end)

so ur ball is just a part,u just need to put this script inside that ball,it still work tho. and about how to make the ball dissapear after launched,this is the full code:

local sound = script.fire 
local tweenservice = game:GetService("TweenService") 
local plr = game.Players.LocalPlayer

local tear1 = game.ReplicatedStorage.Player1tear 
local UIS = game:GetService("UserInputService") 

UIS.InputBegan:connect(function(input) 
if input.KeyCode == Enum.KeyCode.E then 
print("Working") 
sound:Play() 
local clonetear = tear1:Clone() 
clonetear.Parent = game.Workspace 
clonetear.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5 tweenservice:Create(clonetear,TweenInfo.new(1,0,0),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 40,Transparency = 1},Enum.EasingStyle.Quint,Enum.EasingDirection.Out):Play() 
game.Debris:AddItem(2.5,clonetear) -- change the number of time to wait until the ball dissapear,this can be the ball range untill get deleted
end 
end)

8 comments

0

it doesn't work. half of the things are red lined.

0

ohhh so maybe i forgot to put end somewhere,ill try to done the script inside studio when i bring my laptop with me

0

okay thanks anyway!

0

ay man tell me the things i ask u so i can help ya better ;)

0

well its a ball, i want it to have limited range but also dissapear when it touches anything, including a wall or an npc

0

i tried the new script. doesnt work on my projectile. for some reason it works on normal parts

0

erm if ur ball is a model,then u have to make a square as the hitbox,and add the script inside that "hitbox",and i changed the script to work

0

the ball isnt a model, its just a part inside replicated storage

asking for a script that shoots the ball?

local sound = script.fire
local tweenservice = game:GetService("TweenService")
local plr = game.Players.LocalPlayer


local tear1 = game.ReplicatedStorage.Player1tear
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		print("Working")
		sound:Play()
		local clonetear = tear1:Clone()
		clonetear.Parent = game.Workspace
		clonetear.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5
		tweenservice:Create(clonetear,TweenInfo.new(1,0,0),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 40,Transparency = 1},Enum.EasingStyle.Quint,Enum.EasingDirection.Out):Play()
	end
end)

there. keep in mind theres a sound inside the localscript, the projectile(ball) is called Player1tear

1 comment

0

he mean he want to make the ball can damage not can shoot:/

This discussion is preserved as it was. New answers, comments, and votes are closed.