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

[SOLVED] Is it possible to change the parent of an object via localscript?

Asked by
bluzorro 417 Moderation Voter
5 years ago
Edited 5 years ago
local uis = game:GetService("UserInputService")
local debounce = false
local name = "Dave"
local message = "Hey man, what's up?"
local dist = 7

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local playerGui = player:WaitForChild("PlayerGui")

local interact = game.ReplicatedStorage.Interact

while true do
    for i, npc in pairs(workspace.NPCs:GetChildren()) do
        if (char:WaitForChild("HumanoidRootPart").CFrame.p - npc.HumanoidRootPart.CFrame.p).magnitude <= dist then
            interact.Parent = playerGui

            uis.InputBegan:Connect(function(input)
                if input.KeyCode == Enum.KeyCode.E and not debounce and interact.Parent == playerGui then
                    debounce = true
                    game.ReplicatedStorage.Remotes.StartDialog:FireServer(name, message, dist)
                    wait(1)
                    debounce = false
                end
            end)
        else
            interact.Parent = game.ReplicatedStorage
        end
    end
    wait(1)
end

I'm trying to make a magnitude script so that when you're near an npc, it would show a gui. The problem is that it doesn't show the gui.

1
Changes on the client do not replicate to the server, so whatever you do on the client in terms of setting a parent will not save to the server. DeceptiveCaster 3761 — 5y
0
thanks man! bluzorro 417 — 5y

Answer this question