You don’t know where to begin?
What about the documentation?? That should be your first thought when you don’t know something about any api, Roblox’ or not
.
Anyway, here’s my script:
local tweenservice = game:GetService "TweenService"
local userinputservice = game:GetService "UserInputService"
local part = --your part here
userinputservice.InputBegan:Connect(function(already_processed: boolean, input: InputObject)
if already_processed then return end
if input.KeyCode ~= Enum.KeyCode.E or input.UserInputState ~= Enum.UserInputState.Begin then return end
tweenservice:Create(part, TweenInfo.new(1),--add your tween parameters here
{["Transparency"] = part.Transparency == 1 and 0 or 1})--allows for toggling visibility
:Play() --play the result
end)
I’m assuming you mean I don’t have to instantiate a surface Gui, it is already in the part, and with appear you mean transparency? Because there are a lot of ways to make parts appear, by moving them in the player’s vision, by lowering the transparency, by just instantiating them in front of the player, etc…
Here’s an implementation with the other input utility service called: ContextActionService
local tweenservice = game:GetService "TweenService"
local contextactionservice = game:GetService "ContextActionService"
local part = --your part
contextactionservice:BindAction("show_part", function(_, state, obj)
if state ~= Enum.UserInputState.Begin then return end
tweenservice
:Create(part, TweenInfo.new(1), {["Transparency"] = part.Transparency == 1 and 0 or 1})
:Play()
end, false, Enum.KeyCode.E)
also you might want to change properties on the server instead, idk if you want that, maybe you only want one player to see the part idk. But if you want all players to see the part you need to send a remote event call and perform the actions on the server:
--localscript
local remote = --your remote
local userinputservice = game:GetService "UserInputService"
userinputservice.InputBegan:Connect(function(already_processed: boolean, obj: InputObject)
if already_processed or obj.KeyCode ~= Enum.KeyCode.E then return end
remote:FireServer()
end)
--serverscript
local tweenservice = game:GetService "TweenService"
local remote = --your remote
local part = --your part
remote.OnServerEvent:Connect(function(plr: Player)
tweenservice
:Create(part, TweenInfo.new(1), {["Transparency"] = part.Transparency == 1 and 0 or 1})
:Play()
end)
Learn more:
(tell me if I misunderstood something, idk)
Hope this helps!