I want to write a script where a part that becomes walkthrough (CanCollide off) when touched, but the player touching it has to own a badge for it to open.
I don’t have any good source for learning scripting, if anyone has one, please share!
I tried searching on YouTube about some solutions, but the videos just make you put a free model with a script already in it.
I also want the part to be CanCollide off for about 2.5 sec, then CanCollide on.
Please share some tutorials on scripting. Sites, videos, anything.
I would personally recommend AlvinBlox and TheDevKing for beginners.
Official Scripting Documentation will seem extremely confusing in the beginning, but will turn into a really good learning source if you get a handle of it.
Suphi Kaner has probably the best guides on YT that cover advanced scripting concepts.
You can sometimes ask ChatGPT or DeepSeek for advice, but remember to use them as learning tools rather than relying on them solely to get the job done.
local badgeService = game:GetService("BadgeService")
local players = game:GetService("Players")
local part = script.Parent
local badgeID = 1 -- Replace this with your actual badge ID
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
-- Check if player exists
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
-- Make a network request to check if the player has the specified badge
local success, hasBadge = pcall(badgeService.UserHasBadgeAsync, badgeService, player.UserId, badgeID)
if success and hasBadge then -- Check if the request was successful and the player has the badge
part.CanCollide = false -- Allow players to walk through
part.Transparency = 0.75 -- Make the part semi-transparent
wait(2.5) -- Wait for 2.5 seconds
part.CanCollide = true -- Make the part solid again
part.Transparency = 0 -- Make the part fully visible
end
end
end
end)
My apologies for barely putting any effort into this guide, but I hope that this helps you even a little bit.