I'm new to scripting and I'm trying to make a grenade compatible with filtering enabled. In a local test it works like it should, but in a team test the grenade throws but in one specific direction. What I mean by this is that if I aim at a specific point, the grenade could, say, throw behind me as if it was heading toward one specific spot. It's probably something simple I'm missing, but it ALWAYS goes towards the same exact direction no matter which way my character faces. Any help would be greatly appreciated.
Tool = script.Parent function fire(v) Tool.Handle.Fire:play() local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local missile = Instance.new("Part") local spawnPos = vCharacter.PrimaryPart.Position Tool.GripPos = Vector3.new(0, 0.4, 0.5) vCharacter.Torso["Right Shoulder"].CurrentAngle = 3 spawnPos = spawnPos + (v * 8) missile.Position = spawnPos missile.Size = Vector3.new(1,1,1) missile.Velocity = v * 60 missile.Name = "Grenade" missile.BrickColor = BrickColor.new("Medium green") local force = Instance.new("BodyForce") force.force = Vector3.new(0,100,0) force.Parent = missile Tool.Sound:clone().Parent = missile Tool.Kill:clone().Parent = missile Tool.Smoke:clone().Parent = missile Tool.Handle.Mesh:clone().Parent = missile Tool.Script:clone().Parent = missile local counter = Instance.new("ObjectValue") counter.Value = game.Players:GetPlayerFromCharacter(Tool.Parent) counter.Parent = missile counter.Name = "creator" missile.Parent = game.Workspace end Tool.Enabled = true function onActivated() if not Tool.Enabled then return end Tool.Enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then print("Humanoid not found") return end local targetPos = humanoid.TargetPoint local lookAt = (targetPos - character.Head.Position).unit fire(lookAt) wait(0.1) Tool.Parent = nil end script.Parent.Activated:connect(onActivated)
http://robloxdev.com/articles/Converting-From-Experimental-Mode http://robloxdev.com/articles/Building-Games-with-Experimental-Mode-Off
Okay, so for anyone else with this same question, the problem lies within the Humanoid.TargetPoint - basically, this value cannot be accessed from server scripts because it is local. Roblox used to have this be able to be accessed from the server, so many old weapons can be affected. An extremely simple workaround to this is a couple of scripts someone already made to make this accessible from the server like it used to be.
https://www.roblox.com/library/167731549/TargetPoint-Fix-for-FilteringEnabled
Just put the scripts in the right places and you're good to go.