EDIT: Included the entire LocalScript this time
EDIT 2: Fixed in Community Chat
For some stupid reason this UserInputService function wont work at all. It’s in a localscript, located in PlayerGui, however for some reason it wont work. The rest of the script works fine…
01 | local Point = script.Parent.Adornee.Position |
02 |
03 | local Plr = game.Players.LocalPlayer |
04 |
05 | local Active = false |
06 |
07 | |
08 |
09 | while true do |
10 |
11 | wait( 0.1 ) |
12 |
13 | if Plr:DistanceFromCharacter(Point) < 10 then |
14 |
15 | script.Parent.Enabled = true |
16 |
17 | Active = true |
18 |
19 | else |
20 |
21 | if script.Parent.Parent:FindFirstChild( "Quartermaster" ) then |
22 |
23 | script.Parent.Parent.Quartermaster:Destroy() |
24 |
25 | end |
26 |
27 | script.Parent.Enabled = false |
28 |
29 | Active = false |
30 |
31 | end |
32 |
33 | end |
34 |
35 | |
36 |
37 | game:GetService( "UserInputService" ).InputBegan:Connect( function (Input,GPE) |
38 |
39 | if not GPE then |
40 |
41 | if Input.KeyCode = = Enum.KeyCode.E and Active = = true then |
42 |
43 | local UI = game.ReplicatedStorage.Userinterfaces.Quartermaster:Clone() |
44 |
45 | UI.Parent = game.Players.LocalPlayer.PlayerGui |
46 |
47 | end |
48 |
49 | end |
50 |
51 | end ) |
You can’t change the parent of a part in the server directly from within a local script, but you can clone it and set its parent to wherever you want it to go. Also you didn’t define active, so it might be that too, but I won’t be able to tell you. All you would need to change is this:
01 | game:GetService( "UserInputService" ).InputBegan:Connect( function (Input,GPE) |
02 | if not GPE then |
03 | if Input.KeyCode = = Enum.KeyCode.E then |
04 | if Active = = true then |
05 | local UI = game.ReplicatedStorage.UserInterfaces.Quartermaster:Clone() --that's it |
06 | UI.Parent = script.Parent.Parent |
07 | end |
08 | end |
09 | end |
10 | end ) |
You can’t change the parent of a part in the server directly from a LocalScript. You would need to fire remote events to contact the server and the server needs to change the part’s parent.