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

How do you make something happen for only an equipped tool?

Asked by 2 years ago
Edited 2 years ago

So I basically was trying to make a sniper gui when you zoom in but I've been having problems when I finished the code. The sniper scope and gui worked fine but once I've done it once on the sniper it works on the other tools like ak and pistol ect. Here is some of my code Main code

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local transparent = game.StarterGui.Scope.Frame.ImageLabel
local rep = game.ReplicatedStorage
mouse.Button2Down:Connect(function()
    Camera.FieldOfView = 30
    rep.Gui:FireServer()
    script.Parent.Handle.Transparency = 1

end)

mouse.Button2Up:Connect(function()
    Camera.FieldOfView = 70
    rep.GuiOff:FireServer()
    script.Parent.Handle.Transparency = 0
end)

Trigger gui code

local rep = game.ReplicatedStorage

    game.Workspace.Snipa.Equipped:Connect(function()

        rep.Gui.OnServerEvent:Connect(function(player)
            script.Parent.ImageLabel.ImageTransparency = 0
        end)

        rep.GuiOff.OnServerEvent:Connect(function(player)
            script.Parent.ImageLabel.ImageTransparency = 1
        end)
    end)``

Thanks to any help.

1 answer

Log in to vote
0
Answered by 2 years ago
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local transparent = game.StarterGui.Scope.Frame.ImageLabel
local rep = game.ReplicatedStorage
tool.Activated:Connect(function()
    Camera.FieldOfView = 30
    rep.Gui:FireServer()
    script.Parent.Handle.Transparency = 1

end)

tool.Deactivated:Connect(function()
    Camera.FieldOfView = 70
    rep.GuiOff:FireServer()
    script.Parent.Handle.Transparency = 0
end)

Probably this will work

0
Thanks for trying but this does the same exact thing oblox178 0 — 2y
Ad

Answer this question