The goal of this is to make it so that if you're in a zone, it'll give you an option to open the door by pressing Q. This works fine on Studio, but FAILS on the game. This is my script:
S1 = script.Parent.Sensors.S1 S2 = script.Parent.Sensors.S2 Door = script.Parent.Door ST = script.Parent.Sensors.SensorTop SF = script.Parent.Sensors.FloorSensor _G.ActionGUIs = game.ReplicatedStorage.ActionGUIs function Animate() end EntranceDoorDebounce = false _G["OpenEntranceDoor"] = function () if not EntranceDoorDebounce then EntranceDoorDebounce = true Door.BodyVelocity.velocity = Vector3.new(0, 2,0) ST.Touched:connect(function (hit) if hit.Name == "Door" then wait(3) hit.BodyVelocity.velocity = Vector3.new(0, -2, 0) SF.Touched:connect(function (hit) if hit.Name == "Door" then EntranceDoorDebounce = false end end) end end) end end function DealHotkey(hit) if not hit.Parent:FindFirstChild("Humanoid") then return end local Player = hit.Parent Player.Actions.Action.CanDoAction.Value = true Player.Actions.Action.ActionType.Value = "EntranceDoor" local newGUI = _G.ActionGUIs.OpenDoorGUI:Clone() newGUI.Parent = game.Players:FindFirstChild(Player.Name).PlayerGui end function DealHotkey2(hit) if not hit.Parent:FindFirstChild("Humanoid") then return end local Player = hit.Parent Player.Actions.Action.CanDoAction.Value = false Player.Actions.Action.ActionType.Value = "" local datGUI = game.Players:FindFirstChild(Player.Name) if not datGUI.PlayerGui:FindFirstChild("OpenDoorGUI") then return end datGUI.PlayerGui.OpenDoorGUI:Destroy() end S1.Touched:connect(DealHotkey) S2.Touched:connect(DealHotkey) S1.TouchEnded:connect(DealHotkey2) S2.TouchEnded:connect(DealHotkey2)
And the script that calls the actual door movement is located in the player, this is it:
local player = game.Players.LocalPlayer local m = player:GetMouse() m.KeyDown:connect(function (key) if key == "q" then if script.Action.CanDoAction.Value == false then return end if script.Action.CanDoAction.Value == true then local ActionType = script.Action.ActionType.Value if ActionType == "EntranceDoor" then _G.OpenEntranceDoor() end end end end)
If you know what I've stuffed up, please respond. Thanks in advance.
You're trying to use a _G function that was made on the server from the client. Since everything is local in solo mode, this isn't an issue there. However, there are separate script context instances made when a client connects (else your client script would have to wait until they connect to the server to start running).
Basically, your _G function doesn't exist in the context of the LocalScript.