Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would i make my Gun mag Transparency to 1?

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

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)

2 comments

0

when you say index of mag what do you mean by that?

0

late reply but like model.Mag the dot is a index just instead of mag use where ever the mag is

This discussion is preserved as it was. New answers, comments, and votes are closed.