Adronee problem

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    Adornee to every child of the Folder

  2. What is the issue?


    Only goes onto 1 child of the Folder

  3. What solutions have you tried so far?
    I’ve tried doing while wait() do render stepped and all sorts of methods.
    w

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local Clone = script.Parent.Folder.Keys

UserInputService.InputBegan:Connect(function(keycode)
	for i,v in pairs(game.Workspace.Folder:GetChildren()) do
		if (v.NonTween.Center.Position - Player.Position).magnitude <= 6 then
			if keycode.KeyCode == Enum.KeyCode.F then
				if Clone.Adornee == v.NonTween.Center then
					v.Main.RemoteEvent:FireServer()
				end
			end
		end
	end
end)

while wait() do
	for i,v in pairs(game.Workspace.Folder:GetChildren()) do
		if v:IsA("Model") then
			if (v.NonTween.Center.Position - Player.Position).magnitude <= 6 then
				Clone.Adronee = v.NonTween.Center
				Clone.Enabled = true
			else
				Clone.Adronee = script.Parent.Folder
				Clone.Enabled = false
			end
		end
	end
end

No errors:

1 Like

I’m not sure what you tried to achieve with making a loop arround your function. That would only end in making your game more laggy every time the loop runs and I guess you tried that already without loop but it didn’t work as intended. Looping the UserInputService.InputBegan function would end in that you have after 10 sec like 100 events which fire if you press a button but one time is enough. That’s how i would do it:

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local Clone = script.Parent.Folder.Keys

local AdorneedDoor = nil

UserInputService.InputBegan:Connect(function(keycode)
	if keycode.KeyCode == Enum.KeyCode.F then
		if AdorneedDoor then
			if Clone.Adornee == AdorneedDoor.NonTween.Center then
				AdorneedDoor.Main.RemoteEvent:FireServer()
			end
		end
	end
end)

while true do
	for i,v in pairs(game.Workspace.Folder:GetChildren()) do
		if (v.NonTween.Center.Position - Player.Position).magnitude <= 6 then
			Clone.Adornee = v.NonTween.Center -- << this part of the script is not working
			Clone.Enabled = true -- << this part of the script is not working
			AdorneedDoor = v
            break
		else
			Clone.Adornee = script.Parent.Folder -- << this part of the script is not working
			Clone.Enabled = false -- << this part of the script is not working
			AdorneedDoor = nil
		end
	end
	wait()
end
1 Like

I’ve tried doing that as well,

https://streamable.com/tsbw0a

And what was wrong with that what you tried?

1 Like

I’ve tried doing both methods the one I just updated, and the one you replied with. The video I replied was your method.

Might be because it’s spelled Adornee, but who am I to know?

Erm, thats not the problem the problem is it’s not going onto every child of the Folder/iv in loop

I’ve updated the code. Maybe it’s working now.

1 Like

It works now, anyway you can explain how you made it to work?

Good you’re asking the problem was the for loop of your doors folder. I guess you know that the for loop runs everything inside of it and as it hits it end it runs again. Explained easily Door1 is running first in the loop and you’re 6 Studs nearby it than it shows you the adorneed UI but after it ran the code inside the loop there comes Door2 which isn’t 6 Studs near you and it switches the UI off. And the break after switching the UI on simply prevents that other Doors that would get checked in the loop, if you’re near enough them, don’t switch your UI off because you’re too far away from them.Thats the easy but very long way of how I would explain it.

2 Likes

So you just break it after it’s out of the range?

The loop breaks if one Door is found you’re near enough to.