Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this UserInputService function work?

Asked by
Zeluxis 100
5 years ago
Edited 5 years ago

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..

        local Point=script.Parent.Adornee.Position

local Plr=game.Players.LocalPlayer

local Active=false



while true do

wait(0.1)

if Plr:DistanceFromCharacter(Point) < 10 then

script.Parent.Enabled=true

Active=true

else

if script.Parent.Parent:FindFirstChild("Quartermaster") then

script.Parent.Parent.Quartermaster:Destroy()

end

script.Parent.Enabled=false

Active=false

end

end



game:GetService("UserInputService").InputBegan:Connect(function(Input,GPE)

if not GPE then

if Input.KeyCode==Enum.KeyCode.E and Active==true then

local UI=game.ReplicatedStorage.Userinterfaces.Quartermaster:Clone()

UI.Parent=game.Players.LocalPlayer.PlayerGui

end

end

end)
0
You did put this in a local script, right? SteamG00B 1633 — 5y
0
Yeah. Zeluxis 100 — 5y

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

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:

game:GetService("UserInputService").InputBegan:Connect(function(Input,GPE)
    if not GPE then
        if Input.KeyCode==Enum.KeyCode.E then
            if Active==true then
                local UI=game.ReplicatedStorage.UserInterfaces.Quartermaster:Clone() --that's it
                UI.Parent=script.Parent.Parent
            end
        end
    end
end)
0
Thanks, this solved part of the problem however the function wont run whatsoever. When I press 'E' in test, the function wont even acknowledge it. Zeluxis 100 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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.

0
That's not an answer, this belongs in the comments. SteamG00B 1633 — 5y

Answer this question