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

if not hit.Name == then doesn't work?

I was making the script hurts the script when the part touches the part when the part's name is not the owner's name, script:

		local m1 = game.Lighting.Folder.Matches:Clone()
		m1.CFrame = ma.CFrame * CFrame.new(0,3,-7.25)
		m1.Parent = game.Workspace
		m1.Touched:Connect(function(hit)
		if not hit.Name == player.Character.Name then 
			local goal = {}
			goal.Size = Vector3.new(5.63, 5.63, 21.101)
			goal.Transparency = 1
			local goalp = t:Create(m1, TweenInfo.new(1), goal)
			goalp:Play()
			end
		end)

It doesn't even explode (I didn't add the whole script so. This is just the error). (This is was my previous question but the answer I got in the previous question also didn't work.)

3 answers

✓ Accepted answer

Hello there,

I have edited your script.

local m1 = game.Lighting.Folder.Matches:Clone() -- Clones ("Matches")

m1.CFrame = ma.CFrame * CFrame.new(0,3,-7.25) -- Sets the CFrame of the "m1".
m1.Parent = game.Workspace -- Sets the parent of "m1"

m1.Touched:Connect(function(Hit) -- A function to detect if "m1" is touched.

if Hit.Parent.Name ~= game.Players.LocalPlayer.Name then -- Warning : this won't work with VERY advanced custom characters, in this case, add a Parent.

    local goal = {} 

    goal.Size = Vector3.new(5.63, 5.63, 21.101) 

    goal.Transparency = 1 -- Change the transparency.

    local goalp = t:Create(m1, TweenInfo.new(1), goal)

    goalp:Play()

    end
end)

And... the creator version...

local m1 = game.Lighting.Folder.Matches:Clone() -- Clones ("Matches")

m1.CFrame = ma.CFrame * CFrame.new(0,3,-7.25) -- Sets the CFrame of the "m1".
m1.Parent = game.Workspace -- Sets the parent of "m1"

m1.Touched:Connect(function(Hit) -- A function to detect if "m1" is touched.

if Hit.Parent.Name ~= ("cherrythetree") then -- Boop.

    local goal = {} 

    goal.Size = Vector3.new(5.63, 5.63, 21.101) 

    goal.Transparency = 1 -- Change the transparency.

    local goalp = t:Create(m1, TweenInfo.new(1), goal)

    goalp:Play()

    end
end)

And, a way to prevent the function from detecting parts (just in case.)

if Hit.Parent:FindFirstChild("Humanoid") then -- This line... right here, add it to your function  and it will only work for the models that own a Humanoid!

-- Hope i helped!

---- AIphanium

1 comment

0

Thanks! if Hit.Parent.Name ~= game.Players.LocalPlayer.Name then worked!

That's because when the player touches something, the Part objects are what are touching it, not the actual Model object. This means that the hit parameter will be things like the player's LeftHand, or RightFoot, etc.

Instead, you should check hit.Parent, which is the character model that holds all of these parts.

if not hit.Parent.Name == player.Character.Name then
	-- rest of code

Hope this helps! :)

1 comment

0

This still won't work ;-; It says Character is not Parent of Model ;-;

The problem is you're assuming the entire model is being touched. (i.e Player instead of parts like Left Leg)

local m1 = game.Lighting.Folder.Matches:Clone()
m1.CFrame = ma.CFrame * CFrame.new(0,3,-7.25)
m1.Parent = game.Workspace
m1.Touched:Connect(function(hit)
if not hit.Parent.Name == player.Name then --The player's character has the same name as the Player object.
    local goal = {}
    goal.Size = Vector3.new(5.63, 5.63, 21.101)
    goal.Transparency = 1
    local goalp = t:Create(m1, TweenInfo.new(1), goal)
    goalp:Play()
    end
end)

Instead of using hit, which is only the part that touched the brick, use hit.Parent to get the actual model.

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