Hi,
I'm trying to code a script under the ShopGui's Frame, but there seem to be a problem with finding the TextButton in the MainFrame object. Errormessage displayed below
local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character.Humanoid
local BuyToolEvent = game.ReplicatedStorage.BuyToolEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
-- GUI Variables:
local MainFrame = game:WaitForChild(StarterGui.ScreenGui.Frame)
MainFrame.Visible = false
local CloseButton = MainFrame.TextButton
local buy1 = game.MainFrame.Buy1
local buy2 = game.MainFrame.Buy2
local buy3 = game.MainFrame.Buy3
-- Shop Parts:
local ShopActivator = game.Workspace.ShopActivator
local resetPart = game.Workspace.ShopResetTeleport
local function OpenShop(Hit)
-- Since you are working on a local script, I think you can verify the Player like this:
if PlayerService:GetPlayerFromCharacter(Hit.Parent) == Player then
MainFrame.Visible = true
Humanoid.WalkSpeed = 0
end
end
local function CloseShop()
MainFrame.Visible = false
Humanoid.WalkSpeed = 16
HumanoidRootPart.CFrame = resetPart.CFrame
end
local function buytool1()
local tool = ReplicatedStorage.SuperGravityCoil
BuyToolEvent:FireServer(tool)
end
local function buytool2()
local tool = ReplicatedStorage.Bat
BuyToolEvent:FireServer(tool)
end
local function buytool3()
local tool = ReplicatedStorage["Minecraft Diamond Sword"]
BuyToolEvent:FireServer(tool)
end
ShopActivator.Touched:Connect(OpenShop)
CloseButton.MouseButton1Click:Connect(CloseShop)
buy1.MouseButton1Click:Connect(buytool1)
buy2.MouseButton1Click:Connect(buytool2)
buy3.MouseButton1Click:Connect(buytool3)