Detect if touching basepart is of a player's or a character's?

Hey, I’m trying to make the “Suke Suke no Mi” from One Piece.
I’m also trying to make the “Area Invisibility” from GPO.

The thing is, I made it so it releases a sphere hitbox and if it touches a part that’s of an npc’s then
it’ll tween the transparency to 1. If it’s of a player’s then it’ll invoke a remote function to tween the localplayer’s character into 0.5 so they can see their own character but other players shouldn’t be able to see their character.

local functions = {}
local targets = {}
local remote = game.ReplicatedStorage.RemoteEvents.Suke.Invisible

function functions.Start(plr)
	local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tweenservice = game:GetService("TweenService")
	local chr = plr.Character
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	local sphere = script.Sphere:Clone()
	sphere.Parent = workspace.Effects
	sphere.Position = chr.HumanoidRootPart.Position
	local tween = tweenservice:Create(sphere, tweeninfo, {Size = Vector3.new(38.75, 38.75, 38.75)})
	
	for i, part in pairs(chr:GetDescendants()) do
		if (part.Name ~= "HumanoidRootPart" and part:IsA("MeshPart") or part:IsA("Part")  and  part.Name ~= "HumanoidRootPart") then
			local tween2 = tweenservice:Create(part, tweeninfo, {Transparency = 1})
			tween2:Play()
			part.Material = Enum.Material.Glass
		elseif part:IsA("BillboardGui") then
			part.Enabled = false
		elseif part:IsA("Decal") then
			local tween3 = tweenservice:Create(part, tweeninfo, {Transparency = 1})
			tween3:Play()
		end
	end
	
	tween:Play()
	
	local aoe = workspace:GetPartsInPart(sphere)
	
	for i, part in pairs(aoe) do
		if part:IsA("BasePart") then
			if part.Parent:FindFirstChildOfClass("Humanoid") then
				local playur = game.Players:GetPlayerFromCharacter(part.Parent)
				if playur ~= nil then
					if not table.find(targets, playur.Character) then
						for i, k in pairs(part.Parent:GetDescendants()) do
							if (k.Name ~= "HumanoidRootPart" and k:IsA("MeshPart") or k:IsA("Part") and  k.Name ~= "HumanoidRootPart") then
								remote:InvokeClient(playur, 0.7)
							elseif k:IsA("BillboardGui") then
								k.Enabled = false
							end
							table.insert(targets, part.Parent)
						end
					end
				else
					if not table.find(targets, part.Parent) then
						for i, e in pairs(e:GetDescendants()) do
							if (e.Name ~= "HumanoidRootPart" and e:IsA("MeshPart") or e:IsA("Part") and  e.Name ~= "HumanoidRootPart") then
								local tween2 = tweenservice:Create(part, tweeninfo, {Transparency = 1})
								tween2:Play()
								part.Material = Enum.Material.Glass							
							elseif e:IsA("BillboardGui") then
								e.Enabled = false
							elseif part:IsA("Decal") then
								local tween3 = tweenservice:Create(part, tweeninfo, {Transparency = 1})
								tween3:Play()
							end
							table.insert(targets, part.Parent)
						end
					end
				end
			end
		end
	end

	
end

function functions.End(plr)
	local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tweenservice = game:GetService("TweenService")
	local chr = plr.Character
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	local sphere = script.Sphere:Clone()
	sphere.Parent = workspace.Effects
	sphere.Position = chr.HumanoidRootPart.Position
	local tween = tweenservice:Create(sphere, tweeninfo, {Size = Vector3.new(38.75, 38.75, 38.75)})

	for i, part in pairs(chr:GetDescendants()) do
		if (part.Name ~= "HumanoidRootPart" and part:IsA("MeshPart") or part:IsA("Part")  and  part.Name ~= "HumanoidRootPart") then
			local tween2 = tweenservice:Create(part, tweeninfo, {Transparency = 0})
			tween2:Play()
			part.Material = Enum.Material.SmoothPlastic
		elseif part:IsA("BillboardGui") then
			part.Enabled = true
		elseif part:IsA("Decal") then
			local tween3 = tweenservice:Create(part, tweeninfo, {Transparency = 0})
			tween3:Play()
		end
	end

	tween:Play()
	
	for i, k in pairs(workspace:GetChildren()) do
		if table.find(targets, k) then
			for i, part in pairs(k:GetDescendants()) do
				local playur = game.Players:GetPlayerFromCharacter(k)
				if playur ~= nil then
					if (part.Name ~= "HumanoidRootPart" and part:IsA("MeshPart") or part:IsA("Part")  and  part.Name ~= "HumanoidRootPart") then
						remote:InvokeClient(playur, 0)
					elseif part:IsA("BillboardGui") then
						part.Enabled = true
					end
				else
					if (part.Name ~= "HumanoidRootPart" and part:IsA("MeshPart") or part:IsA("Part")  and  part.Name ~= "HumanoidRootPart") then
						local tween2 = tweenservice:Create(part, tweeninfo, {Transparency = 0})
						tween2:Play()
						part.Material = Enum.Material.SmoothPlastic
					elseif part:IsA("BillboardGui") then
						part.Enabled = true
					elseif part:IsA("Decal") then
						local tween3 = tweenservice:Create(part, tweeninfo, {Transparency = 0})
						tween3:Play()
					end
				end
			end
		end
	end
end

return functions

This is my modulescript.
It gets required by a remote event that gets fired from a localscript.
image

When I do the ability, it does turn the player’s character invisible on server side and the player’s character’s transparency to 0.5 in client. But it doesn’t do it for npcs or other players.
This is the localscript that’s being used in the tool to fire the remote event and require the module to do the move. Its where I set the player that used the move’s client side invisibility to 0.7. but for other players there’s a invisibility localscript for the client to be invoked.

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local Modules = RS:WaitForChild("Modules")
local Fruit = Modules:WaitForChild("Fruit")
local HM = Modules:WaitForChild("Handlers")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local remote = RS.RemoteEvents.Fruit
local PlayerGui = Player:WaitForChild("PlayerGui")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Cooldown1 = false
local Holding1 = false
local Cooldown2 = false
local Holding2 = false
local Debounce = 1
local Mouse = Player:GetMouse()
local track1 = Humanoid:LoadAnimation(Tool.Animations.Spin)
local tweeninfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local ts = game:GetService("TweenService")

local function zmove()
	Tool.Active.Value = "Z"
	remote:FireServer("Suke", "Self Invisibility", "Start")
	wait(2)
	for i, v in pairs(Character:GetDescendants()) do
		if (v.Name ~= "HumanoidRootPart" and v:IsA("MeshPart") or v:IsA("Part")  and  v.Name ~= "HumanoidRootPart") then
			v.Transparency = 0.7
		elseif v:IsA("Decal") then
			v.Transparency = 0.7
		end
	end
	wait(10)
	for i, v in pairs(Character:GetDescendants()) do
		if (v.Name ~= "HumanoidRootPart" and v:IsA("MeshPart") or v:IsA("Part")  and  v.Name ~= "HumanoidRootPart") then
			v.Transparency = 0
		elseif v:IsA("Decal") then
			v.Transparency = 0
		end
	end
	remote:FireServer("Suke", "Self Invisibility", "End")
	Tool.Active.Value = "None"
end

local function xmove()
	Tool.Active.Value = "Z"
	remote:FireServer("Suke", "Area Invisibility", "Start")
	wait(2)
	for i, v in pairs(Character:GetDescendants()) do
		if (v.Name ~= "HumanoidRootPart" and v:IsA("MeshPart") or v:IsA("Part")  and  v.Name ~= "HumanoidRootPart") then
			v.Transparency = 0.7
		elseif v:IsA("Decal") then
			v.Transparency = 0.7
		end
	end
	wait(10)
	remote:FireServer("Suke", "Self Invisibility", "End")
	Tool.Active.Value = "None"
end

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E and Debounce == 1 and Tool.Equip.Value == true and Tool.Active.Value == "None"  and Cooldown1 == false then
		Debounce = 2
		local HIS = Tool.Animations["Area Charge"]
		HoldTrack = Player.Character.Humanoid:LoadAnimation(HIS)
		HoldTrack:Play()
		for i = 1,math.huge do
			if Debounce == 2 then
				local RootPos, MousePos = Player.Character.HumanoidRootPart.Position, Mouse.Hit.Position
				Player.Character.HumanoidRootPart.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
				Player.Character.HumanoidRootPart.Anchored = true
			else
				break
			end
			wait()
		end
	elseif Input.KeyCode == Enum.KeyCode.Z and Tool.Equip.Value == true and Tool.Active.Value == "None"  and Cooldown1 == false then
		track1:Play()
		zmove()
		Cooldown1 = true
		wait(3)
		Cooldown1 = false
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E and Debounce == 2 and Tool.Equip.Value == true and Tool.Active.Value == "None" and Cooldown1 == false then
		Cooldown1 = true
		Debounce = 3
		local PIS = Tool.Animations["Area Release"]
		local PunchTrack = Player.Character.Humanoid:LoadAnimation(PIS)
		PunchTrack:Play()
		HoldTrack:Stop()
		PunchTrack:GetMarkerReachedSignal("Release"):Connect(function()
			xmove()
			task.wait(3)
			Cooldown1 = false
		end)
		wait(1)
		Player.Character.HumanoidRootPart.Anchored = false
		wait(2)
		Tool.Active.Value = "None"
		wait(0.1)
		Debounce = 1
	end
end)

This is the invoke thingy:

local rs = game:GetService("ReplicatedStorage")
local re = rs.RemoteEvents
local invisiblevent = re.Suke.Invisible

invisiblevent.OnClientInvoke = function(transparency)
	for i, v in pairs(game.Players.LocalPlayer.Character:GetDescendants()) do
		if (v.Name ~= "HumanoidRootPart" and v:IsA("MeshPart") or v:IsA("Part")  and  v.Name ~= "HumanoidRootPart") then
			v.Transparency = transparency
		elseif v:IsA("Decal") then
			v.Transparency = transparency
		end
	end
end
1 Like

Generally doing:

if hit.Parent:FindFirstChild("Humanoid") then

would work. However, if you have NPCs, you may wish to do this instead:

if game.Players:GetPlayerFromCharacter(hit.Parent) then
2 Likes

What do you mean by “other players”. Do you mean the script only works on your roblox account? Also, do you or do you not want it to work on the NPC?

If you want it to work on the NPC, to somethings like this:

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            --loop through character and set transparency to 0
            --send remote event/function so that player can see itself as half transparent
        else
            --loop through character and set transparency to 0
        end
    end
end)

If it worked please set as solution thanks! :slight_smile:

I want it so every NPC/Player that touches the sphere that I release, will be affected.
and if it’s a player then it’ll invoke a certain remotefunction

Ok. Did you try out my code tho? If you don’t know how I can give you full code but not on devforums because its against the rule. That’s the most I can give you.

You can differentiate between player character instances and NPC instances by using the following.

if game.Players:GetPlayerFromCharacter(Character) then
	--this is a player
else
	--this is not a player
end

if game:GetService("Players"):GetPlayerFromCharacter(Character) then
	--this is a player
else
	--this is not a player
end

please mark a solution, a few people also answered correct above.

local isPlayer = game.Players:GetPlayerFromCharacter(Character)
if isPlayer then
--do code if they are a player and if they aren't you can add a else below if you want to do something different between npcs and players.
end

I’ve made it detect if the model is inside “Player” folder in workspace then it’s a player and the same for npcs, ‘NPC’ Folder.

I mean the way I posted above is the most used and “correct” way but whatever works for you, if you’ve figured it out I guess you can mark someone as a solution

Sorry didn’t see there was alot more to the post

1 Like

This guy just damn trolling people he doesn’t set solution smh

Please. I’m not trolling people. Why would I set solution when I found a way myself? Act more mature, thanks.

You should close the topic if you " found a way yourself". Or else you are wasting other people’s time.

1 Like

I don’t know how to I’ll try to close it

search it up ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎

1 Like