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

Why isnt both functions not working?

Asked by 7 years ago

I actually have two questions. How can I make it so that the SurfaceGui brick will spawn next to me on my right side at all times? It keeps spawning either in front of me or to the opposite side. Also I wanted it to be able to spawn the Surface Gui brick when I press e or the actual GUI button. But I can only spawn it by pressing the GUI button. Your help will be much appreciated! Thanks!

local plr = game.Players.LocalPlayer
local chr = plr.Character
local mouse = game.Players.LocalPlayer:GetMouse()
local screenBrick = game.ReplicatedStorage.inventoryScreen
local button = script.Parent
local buttonDeb = false
local keyDeb = false

function spawnScreen()
    local  sb = screenBrick:Clone()
    sb.Parent = game.Workspace
    sb.Anchored = true
    sb.CanCollide = false
    sb.CFrame = chr.Head.CFrame + Vector3.new(-2,0,6)
    for i = 1,0.3,-0.1 do
        sb.SurfaceGui.container.BackgroundTransparency = i
        wait()
    end
end

button.MouseButton1Click:connect(function(click)
    if buttonDeb == false then buttonDeb = true
        spawnScreen()
    end
end)

local function onKeyDown( key )
    if keyDeb == false then keyDeb = true
        if key == "e" then
            spawnScreen()
        end
    end
end
mouse.KeyDown:connect(onKeyDown)

Answer this question