Projectile SERVERSCRIPT

game.ReplicatedStorage.Light.OnServerEvent:Connect(function(player, keyheld, debounce, mousepos)
	print(keyheld)
	if keyheld == true then
		local light = game.ReplicatedStorage.LightPart1:Clone()
		light.Parent = workspace
		light.CFrame = player.Character.RightFoot.CFrame
		local weld = Instance.new("Weld")
		weld.Parent = light
		weld.Part0 = light
		weld.C0 = light.CFrame:Inverse()
		weld.Part1 = player.Character.RightFoot
		weld.C1 = player.Character.RightFoot.CFrame:Inverse()
	end
	if not keyheld then
		if game.Workspace:FindFirstChild("LightPart1") then
			game.Workspace.LightPart1:Destroy()
			local ball = game.ReplicatedStorage.LightBall:Clone()
			ball.Parent = player.Character
			ball.CFrame = player.Character.RightFoot.CFrame
			local bv = Instance.new("BodyVelocity")
			bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bv.Velocity = mousepos.lookVector*90
			bv.Parent = ball
		end
	end
end)

Projectile Hit Detection LOCALSCRIPT

script.Parent.Touched:Connect(function(hit)
	print("Hit1")
	local ehum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
	local debounce = false
	if ehum and ehum ~= game.Players.LocalPlayer.Character.Humanoid and debounce == false then
		game.ReplicatedStorage.Hit:FireServer(ehum)
	end
	if not ehum and debounce == false then
		game.ReplicatedStorage.Hit:FireServer(hit)
	end
end)

The entire thing works fine if I parent the "Ball" projectile to the Character Model, but it doesn't work when its parented anywhere else even though I'd much prefer it to be parented in workspace.

6 comments

1

Because local scripts don't run in workspace but they will run in a player's character model, you shouldn't be listening for touched events with a local script anyway...only use the serverscript

0

OMG, I'm such an idiot, some how I completely forgot that localscripts don't run in certain places, Thanks. Been trying so hard to learn Remote events etc that I'd forgotten the basics.

0

no worries, it is easy to forget

0

It's perfectly fine to listen for touched events in local scripts.

0

Check the wiki to see where the different script types run

0

@RayCurse wouldn't recommend it at all, say that his character died then the touched event would cease to function...not to mention the kind of power you'd be giving the client