I made some obby fading squares for my obby

hey guys im having a weird issue so i have made fading squares for my obby using this script local CollectionService = game:GetService(“CollectionService”)
local TAG_NAME = “Fade” – replace this with the tag you want to use

local function fade(part)
if CollectionService:HasTag(part, TAG_NAME) then
local isTouched = false
if not isTouched then
isTouched = true
for count = 1,10 do
part.Transparency = count / 5
wait(0.10)
end
part.CanCollide = false
wait(10)
part.CanCollide = true
part.Transparency = 0
isTouched = false
end
end
end

– Connect the function to the Touched event of all parts with the tag
for _, part in ipairs(CollectionService:GetTagged(TAG_NAME)) do
part.Touched:Connect(function()
fade(part)
end)
end now what is happening is that once the square is faded to where it becomes transparent the can collide does not kick in right when then square fully goes transparent like when i stand on it its roughly 2 to 3 seconds then it allows me to fall through. to add to that when it reappears it flickers transparent to solid then it fixes it self being solid again i have no idea how to fix it this script was something i tossed together real fast this is what happens once stepped on one of the squares


after it goes transparent within the 1 or 2 seconds it will then allow me to fall through is there a way i can make it to where right as it goes transparent the player falls i would like to use the script as the collectionservice instead of putting scripts in alot of parts thank you guys in advanced

1 Like

You could simplify the script greatly and kinda easily (depending on your Lua knowledge).


Create a folder in the workspace, put all of the parts into the folder, add a script into the folder, and use my code below.

Code
-- >>: Variables
local tweenService = game:GetService("TweenService")

local folder = script.Parent

local tweenInfo = TweenInfo.new(0.75, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)

-- >>: Main Code
for i, part in pairs(folder:GetChildren()) do
	if part:IsA("BasePart") then
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				tweenService:Create(part, tweenInfo, {Transparency = 1}):Play()
				task.wait(tweenInfo.Time)
				part.CanCollide = false
				
				task.wait(math.random(5,8))
				
				tweenService:Create(part, tweenInfo, {Transparency = 0}):Play()
				task.wait(tweenInfo.Time)
				part.CanCollide = true
			end
		end)
	end
end

what i did for my other models is that just grouped the parts then put a script in the model itself above the parts then just smack the parts with the tag editor but since it was tagged i just dont get why its flickering and being wonky im still new at learning lua but making obbys and using the collectionservice and tagging stuff is kinda new to me

it fixed the flickering issue thank you but when i stand on it and it turns cancollide is there a way i could speed part up by any chance like it goes transparent but that 1-2 second delay before it throws me through it still happens

amora i have another question for ya so for some parts whats the purpose for people putting welds inside of the part like what does welds do?

Like in free models?
99% of the time in free models, those welds don’t even connect any parts. They are entirely useless.


The purpose of welds is to link two parts together, like in tools. Tools cannot be anchored, so you will always weld the parts of tool to the tool’s handle so it will not fall apart.

yea free models in a way bit i just wasnt sure so for example a better use for welds is if your making a car and you only want a certain thing to move like wheels there for the parts move together?

Yes, that is the exact reason why. It restrains parts in there position. Think of the weld like welding two metal plates together in real life. It sticks them in their position, as well as it allows them to stay there unanchored and move with each other.

The wheels wouldn’t be welded to anything (unless you put them on an axle, then they would be welded to that).


When using free models, I would always recommend checking the properties of the welds if they have any. Check the Part0 and Part1 properties. If they have a Part0, but not a Part1, then it is useless.

I would also recommend just not using free models because they can very easy have viruses. If you insist on using them, I would recommend installing the Ro-Defender Virus Remover plugin and scanning your game with it every time you insert a free model (unless uploaded by Roblox themselves. Otherwise you cannot fully trust it).

yea i make my own models i was just wondering the reason for it as a checkerboard obby theres 0 point in having welds becuse its not doing anything besides kill player when touched

In that case, the welds are useless then.

so i have another question for ya scripts for like obby models right if i was to put it in server script service could someone backdoor it or exploit it and if the script is placed within the model it self can a exploiter gain accesses to it?

It depends on the context, but if the script is a virus, then yes they can.

was not sure thats why i wanted to ask becuse i know that scripts in serverscript service they cant edit so i just did not know if you make a model slap a script within the model if players can some how get accesses to it or able to back door it i just wanted to recheck myself as say i take the scripts from the models toss them in server script service if that would be more protective instead of having the script in the model

Most viruses give complete control of your game to the owner of the model, despite where it is in the game. Including ServerScriptService. But I may be wrong about that. I’m not entirely sure. My only knowledge on how backdoor viruses work is caveman knowledge: “Virus bad, no want.”

I’m going to simplify @AmoraFolf 's code as some parts are unnecessary.

Tweensvc = game:GetService("TweenService")
folder = script.Parent
info = TweenInfo.new(.75, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)
function Tween(item, info, goal, Wait)
    local tw = Tweensvc:Create(item, info, goal) -- Creates tween
    tw:Play() -- Plays tween
    if Wait then
        tw.Completed:Wait() -- Yields code until Event is fired
    end
end


-- within code:
part.CanCollide = false
Tween(part, info, {Transparency = 1}, true) -- Tweens with yielding

task.wait(math.random(5, 8))
part.CanCollide = true
Tween(part, info, {Transparency = 1}, true)

thank you for giving me some answers to my questions i hope i didnt annoy you or anything. where i started with roblox was making cars so me trying to make my own scripts from scratch is all new

1 Like

The simplified version is much better and neater. Some of my code was pretty unnecessary.

1 Like

its all good i tend to start scripts off messy but try to find videos to clean it up some there for its not tossed around and messy but if it works at first i dont mess with it untile i finish the project then come back and clean it up or try too as best i can

im getting a error of attemot to indec nil with cancollide under the within code: how can i fix it?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.