How to make a door that disappear when you meet a certain requirement

Hello everyone,
I’ve been trying to make a client-sided door for my game that disappears when touched. I tried with the script below but it doesn’t seem to work
newnewscript
Any help would be greatly appreciated

I would thank you a lot if you paste just the code so I can test with it.

here it is
local function parttouched(ptouched)
if game:GetService(“Players”).LocalPlayer.leaderstats.Rank.Value >= 5 then
script.Parent.Transparency = 1
script.Parent.Cancollide = false
end
end

script.Parent.Touched:Connect(parttouched)

I can show you a thing or two.

To make the door disappear only for a certain player when they touch the activation button (or part), First we would add a LocalScript inside of StarterPlayer > StarterCharacterScripts.

Did you know that there was a such thing called a Humanoid.Touched function? Yes, we are going to use that.

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local stats = player:WaitForChild("leaderstats").Cash
local humanoid = character:WaitForChild("Humanoid")

local function touch_door (object)
	if object:IsA("Part") and object.Name == "Door" and stats.Value >= 5 then
		print(stats.Value)
		object:Destroy()

		-- << object.Transparency = 1
		-- << object.CanCollide = false

		return object
	end
end

humanoid.Touched:Connect(touch_door)

This should work decently.

One more thing, this code should only work for the player that is touching the part, so no one else can get inside and stuff.

2 Likes

The issue with the provided code is that it is not checking if the touched part is the door itself. The code should also be checking if the player is touching the door and not some other part in the game. Here is a possible fixed code:

local door = script.Parent
local player = game:GetService("Players").LocalPlayer

local function onPartTouched(part)
    if part == door and player.leaderstats.Rank.Value >= 5 then
        door.Transparency = 1
        door.CanCollide = false
    end
end

door.Touched:Connect(onPartTouched)

In this code, we first get a reference to the door and the LocalPlayer. Then, we create a function called onPartTouched that takes in a parameter part. Inside the function, we first check if the touched part is the door itself using the equality operator ==. If the condition is true and the player’s rank is greater than or equal to 5, we make the door transparent and disable its collision. Finally, we connect the function to the Touched event of the door.

Create a remote event that checks to see if you have the requirements on the server side, and if you do then that remote event will fire a client remote event that makes the collision false.

I get the error “Workspace.TheCursedRobIoxian.LocalScript:8: attempt to compare number <= string”
on line 8 "if object:IsA(“Part”) and object.Name == “PrestigeAreaDoor” and stats.Value >= 5 then

It’s because your rank leaderstats is a string value not a number value.

show me your edited code so i can solve this problem.

i changed it to string value and it works. thank you so much. i’ve been on this for like 5 months

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