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

How would i make my Gun mag Transparency to 1?

Asked by 5 years ago

hello there, In most of all guns they have a "OnKeyDown" function that when you press r that reloads the gun. What i am trying to do is make the guns mag which is a meshpart in side the gun tool, to turn the transparency to 1, that way, when the reload animation plays, the mag transparency would be 1, and when the animation stops the transparency would go back to normal.

How would i type that in this line of code? thanks for help!

function OnKeyDown(key)
    if string.lower(key) == 'r' then
        Reload()
        if RecoilTrack then
            RecoilTrack:Stop()
        end
    end
end

1 answer

Log in to vote
0
Answered by 5 years ago

this is gonna be alot this assumes mag is one part/ a union first of all keydown or whatever is deprecated do this make sure its a local script

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(Input)
if Input.Keycode == Enum.Keycode.R then
 Reload()
  if RecoilTrack then
 RecoilTrack:Stop()
end
end
end)

Now add a Remote event to replicated storage Name it SetTransparency Now go back to the local script and put this code in Idk where your mag is so i will use mag you put the index of the mag

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(Input)
if Input.Keycode == Enum.Keycode.R then
 Reload()
  if RecoilTrack then
 RecoilTrack:Stop()
end

game.RepliactedStorage.SetTransparency:FireServer(mag, 1)

end
end)

now go to server script service add a script then put this script in it

game.RepliactedStorage.SetTransparency.OnServerEvent:Connect(function(plr, object, trans)
object.Transparency = trans
end)
0
when you say index of mag what do you mean by that? Carforlife1 59 — 5y
0
late reply but like model.Mag the dot is a index just instead of mag use where ever the mag is mattchew1010 396 — 5y
Ad

Answer this question