How to make a closet mechanic like in doors?

So,i have a working script to hide,but i just dont know how to access “kurya” from a script.
Anyways,here’s the script:

local kurya = game:GetService("Workspace"):FindFirstChild("Assets"):FindFirstChild("Kurya")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		script.Parent.Triggered:Connect(function()
			character.Humanoid.WalkSpeed = 0
			character.HumanoidRootPart.CFrame = script.Parent.Parent.CFrame
			game:GetService("StarterGui").healthinvcam.button.MouseButton1Click:Connect(function()
				character.Humanoid.WalkSpeed = 16
				character.HumanoidRootPart.CFrame = workspace.hiddenpart1.CFrame
			    end)
			end)
	end)
end)

1 Like

0 specification on what kurya or any of this stuff does. I see you disable their movement and CFrame them into the hiding area but why using startergui? Player Gui is how to access people’s gui. I also don’t really recommend using the server for this… a little bit of lag and your CFrames won’t work properly. Anytime you are handling game mechanics it is always better to use local scripts. Handle information(Example: Data Stores) on the server and mechanics(Example: Humanoid properties) on the client

4 Likes

Use this in a local script. You’re welcome.

local plr = game.Players.LocalPlayer
local char = plr.Character

plr.PlayerGui.healthinvcam.button.MouseButton1Click:Connect(function() --makes the gui clickable

if char and char:FindFirstChild('Humanoid') and char:FindFirstChild('HumanoidRootPart') then --checks the parts we are accessing to make sure we are not accessing non-existent parts of their character

char.Humanoid.WalkSpeed = 0

char.HumanoidRootPart.CFrame = script.Parent.Parent.CFrame --Change this to the part that it originally was not using script parent the actual part name

task.wait(4) --delay so that they can't move for 4 seconds when CFraming

char.Humanoid.WalkSpeed = 16

char.HumanoidRootPart.CFrame = workspace.hiddenpart1.CFrame

end

end)
2 Likes

look,i think you didnt actually undestand what i meant.all i need is to access “kurya” and make his “Damage” script enabled to false when in the closet.

I gave you a completely working script with detailed information how it works and what you should do with it. It goes in a local script so you can click that “healthincam” button. I still have no idea what kurya is. Unless you post a picture of your workspace, you are on your own with disabling the damage script. Please try and be more specific next time so we can help you. Thank you!

1 Like

kurya is a rush entity that gets clonned with a chance in assets

1 Like

when i try to print kurya,it just says nil,even when he is in the workspace

1 Like

here’s the script of spawning kurya:

wait(3)
local kurya = game:GetService("ReplicatedStorage"):FindFirstChild("Kurya"):Clone()

local hitpart = kurya:FindFirstChild("hitpart")
local approach = kurya:FindFirstChild("Approach")

local digus

while wait(1) do
	print("approaching!")
	approach:Play()
	
	digus = math.random(120,250)
	
	kurya.Parent = workspace:FindFirstChild("Assets")
	kurya.CanCollide = false
	kurya.CFrame = workspace:FindFirstChild("smth1").CFrame
	hitpart.CFrame = workspace:FindFirstChild("smth1").CFrame
	
	while wait(.0000005) do
	for hui = 0,35 do
	kurya.Position = kurya.Position + Vector3.new(0,0,math.cos(tick()/2))
	hitpart.Position = hitpart.Position + Vector3.new(0,0,math.cos(tick()/2))
    end
	end
end
1 Like

It’s because you are trying to clone it before it actually exists. I can show you how to clone him properly. You will obviously need to use a remote event for this to work because we need to pass information to the server to clone create the rush entity. I can help you do this.

1 Like

i will be very glad if you would help me with that

2 Likes
--Put this LOCAL script in startercharacterscripts
local plr = game.Players.LocalPlayer
local char = plr.Character
local rs = game.ReplicatedStorage

plr.PlayerGui.healthinvcam.button.MouseButton1Click:Connect(function()

rs.Kurya_Event:FireServer() --Create a remote event named "Kurya" in replicated storage and let this do the work for you

if char and char:FindFirstChild('Humanoid') and char:FindFirstChild('HumanoidRootPart') then

char.Humanoid.WalkSpeed = 0

char.HumanoidRootPart.CFrame = script.Parent.Parent.CFrame

char.Humanoid.WalkSpeed = 16

char.HumanoidRootPart.CFrame = workspace.hiddenpart1.CFrame

end

end)
--Put this SCRIPT(Not Local) in serverscriptservice
local kurya = game:GetService("ReplicatedStorage"):WaitForChild("Kurya_Entity"):Clone()
local hitpart = kurya:WaitForChild("hitpart")
local approach = kurya:WaitForChild("Approach")

game.ReplicatedStorage.Kurya_Event.OnServerEvent:Connect(function()

wait(3)

local digus

while wait(1) do

print("approaching!")

approach:Play()
	
digus = math.random(120,250)
	
if workspace:FindFirstChild("Assets") and workspace:FindFirstChild("smth1") then

kurya.Parent = workspace.Assets
kurya.CanCollide = false
kurya.CFrame = workspace.smth1.CFrame
hitpart.CFrame = workspace.smth1.CFrame

end

	
while wait(.0000005) do

for hui = 0,35 do
kurya.Position = kurya.Position + Vector3.new(0,0,math.cos(tick()/2))
hitpart.Position = hitpart.Position + Vector3.new(0,0,math.cos(tick()/2))
end --end for loop

end --end second while wait loop

end --end first while wait loop

end) --end remote event
1 Like

You need to create a remote event named “Kurya_Event” put it in replicated storage, rename Kurya the entity that is already in replicated storage to “Kurya_Entity”, and put the scripts where it says to put them.

1 Like

[/quote]

robloxapp-20240927-2034224.wmv (239.3 KB)

1 Like

when you hide in the closet,ALL i need is to kurya to not hit you when you hide in the closet.i only need that

1 Like

also thx for the revamp of the serverscriptservice script

2 Likes
--Put this LOCAL script in startercharacterscripts
local plr = game.Players.LocalPlayer
local char = plr.Character
local rs = game.ReplicatedStorage

plr.PlayerGui.healthinvcam.button.MouseButton1Click:Connect(function()

if char and char:FindFirstChild('Humanoid') and char:FindFirstChild('HumanoidRootPart') then

char.Humanoid.WalkSpeed = 0

char.HumanoidRootPart.CFrame = script.Parent.Parent.CFrame

local In_Closet = Instance.new("StringValue")
In_Closet.Parent = char
In_Closet.Name = "In_Closet"

rs.Kurya_Event:FireServer(In_Closet)

task.wait(4)

In_Closet:Destroy()

char.Humanoid.WalkSpeed = 16

char.HumanoidRootPart.CFrame = workspace.hiddenpart1.CFrame

end

end)
--Put this SCRIPT(Not Local) in serverscriptservice
local kurya = game:GetService("ReplicatedStorage"):WaitForChild("Kurya_Entity"):Clone()
local hitpart = kurya:WaitForChild("hitpart")
local approach = kurya:WaitForChild("Approach")

game.ReplicatedStorage.Kurya_Event.OnServerEvent:Connect(function(player, In_Closet)

wait(3)

local digus

while wait(1) do

print("approaching!")

approach:Play()
	
digus = math.random(120,250)
	
if workspace:FindFirstChild("Assets") and workspace:FindFirstChild("smth1") then

kurya.Parent = workspace.Assets
kurya.CanCollide = false
kurya.CFrame = workspace.smth1.CFrame

if In_Closet then
hitpart.CFrame = workspace.smth1.CFrame
end

end

	
while wait(.0000005) do

for hui = 0,35 do
kurya.Position = kurya.Position + Vector3.new(0,0,math.cos(tick()/2))
hitpart.Position = hitpart.Position + Vector3.new(0,0,math.cos(tick()/2))
end --end for loop

end --end second while wait loop

end --end first while wait loop

end) --end remote event

I am assuming that the hitpart is what kills them so basically what this does is it checks if they are in the closet and if they are it will not kill them otherwise it will

1 Like

Try using problem solving skills and figure out how to do each part of your script instead of asking someone else to do it for you

2 Likes

Let me know what happens. It’s very hard to do this without seeing what’s in the workspace so i’m just guessing at this point which does which because it is labeled very poorly lol. I would imagine it’s pretty close to working though so it would only be something small needed to be changed if this doesn’t work

i dont have enough experience to do something like that