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

Can you save the brick on mouse.Target?

So I'm making a thing where if you press E it will make the object fade away like this: ~~~~~~~~~~~~~~~~~

				mouse.Target.Transparency = .1
				wait(.01)
				mouse.Target.Transparency = .2
				wait(.01)
				mouse.Target.Transparency = .3
				wait(.01)
				mouse.Target.Transparency = .4
				wait(.01)
				mouse.Target.Transparency = .5
				wait(.01)
				mouse.Target.Transparency = .6
				wait(.01)
				mouse.Target.Transparency = .7
				wait(.01)
				mouse.Target.Transparency = .8
				wait(.01)
				mouse.Target.Transparency = .9
				wait(.01)
				mouse.Target:destroy()


BUT!  If you move your mouse to another object that one will start fading.

because I have this to keep it to only my rocks in the country. (dont ask)

if mouse.Target.parent.Name == "RocksOfTheCountry" then

so is there a way to save what brick your mouse was on and only do the transparency to that object?

4 comments

0

I messed up with the code blocks just ignore that please couldnt figure it out

0

You can edit and preview the question there is no reason not to mess it up o.o

0

You would just pass mouse.Target to a variable ie local part = mouse.Target then use part

0

Use the If statement that DeviantProphet proposed. I don't know how yours look and that might have been the problem.

2 answers

hopefully i can help with this

local uis = game:GetService("UserInputService")
local mouse = player:GetMouse()

uis.InputBegan:connect(function(input,isTyping)
	if input.KeyCode == Enum.KeyCode.Z and not isTyping and mouse.Target.Parent.Name == "RocksOfTheCountry" then
		for i = 1,10 do
			mouse.Target.Parent.Transparency = mouse.Target.Parent.Transparency - 0.1
			wait(0.1)
		end
		mouse.Target.Parent:Destroy()
	end
end)	

of couse you'll have to change some things from this script because i don't know most of you're variables and stuff, but this should help.

I think its hitting multiple targets because it looks like you constantly have mouse.Target.Parent updating so everytime you go over a object while its active it will pass on to them, this should hopefully preven that

also note: using User Input Service instead of the normal way is more efficient thats why i used it in this example, but like i said before you'll most likely need to edit this so dont just copy and paste this whole thing in and expect it to work

In your "If" statement put

local function FadeAway(Target)
	Target.Transparency = .1
	wait(.01)
	Target.Transparency = .2
	wait(.01)
	Target.Transparency = .3
	wait(.01)
	Target.Transparency = .4
	wait(.01)
	Target.Transparency = .5
	wait(.01)
	Target.Transparency = .6
	wait(.01)
	Target.Transparency = .7
	wait(.01)
	Target.Transparency = .8
	wait(.01)
	Target.Transparency = .9
	wait(.01)
	Target:destroy()
end

if (conditions) then
	if mouse.Target:IsA("BasePart") then
		spawn(function() 
			FadeAway(mouse.Target)
		end)
	end
end

I used spawn(function() end) so that it will run on another thread and doesn't lock your code up. The mouse.Target is "saved" and passed to the function FadeAway(). If you're only looking for brick pieces then you might want to add a check for "BasePart".

I'll just add that in.

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