我的武器只对NPC有效,对玩家无效



所以基本上我制作了一种武器,它会在你击中人后把人扔出去,但它只对NPC有效,对玩家无效。有人能给我解释一下这是为什么吗?

local power = 5
local function fling(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
local rootpart
if humanoid then
humanoid:ChangeState(11)
rootpart = humanoid.RootPart
end
if not rootpart then
rootpart = character.AssemblyRootPart
end
if rootpart then
rootpart.Velocity = Vector3.new(math.random(-100, 100), math.random(50, 100), math.random(-100, 100)) * 10
end
end
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local slash = script:WaitForChild("Slash")
local debounce = false
local idle = false
local PlayersHit = {}
local playerService = game:GetService("Players")
local plr = playerService:GetPlayerFromCharacter(tool.Parent)
local Datastore2 = require(game.ServerScriptService:WaitForChild("Modules").Datastore2)
local defaulthits = 0
local hitds = Datastore2("hits",plr)
tool.Activated:Connect(function()
if idle == false and debounce == false then 
debounce = true

local humanoid = tool.Parent:WaitForChild("Humanoid")
local animtrack = humanoid:LoadAnimation(slash)

animtrack:Play()
wait(1)
debounce = false
idle = false
end
end)
handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= tool.Parent then
if debounce == true and PlayersHit[hit.Parent] == nil then

fling(hit.Parent)
hitds:Increment(1, defaulthits)
debounce = false
script.Parent.Handle.hit:Play()
end
end
end)

这是我当前的代码。我不知道该怎么办,我很确定这是与投掷脚本有关。

我发现如何代替humanoid:changestate(11)我使用humanoid。PlatformStand = true

最新更新