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

touched:connect() not working with a fading gui?

Asked by 5 years ago

If you see here,

game.Workspace.Room.Door.Stuff.Touched:connect()
script.Parent.Visible = true
wait(1)
local tweenservice = game:GetService("TweenService")
local fadebackground = script.Parent --background

local tweenInfo = TweenInfo.new(
3,--time
Enum.EasingStyle.Sine, --smooth
Enum.EasingDirection.Out, --dont change
0, -- dont change
true, --false = fade out true = fade in
0
)

local tween = tweenservice:Create(fadebackground, tweenInfo, {BackgroundTransparency = 1})
tween:Play()
end)
end)

It just won't run. If anyone could help, that would be greatly appreciated. I just don't know what's wrong. If you have questions or need more information, just reply.

Thanks!!

0
It must be connected to a function. DeceptiveCaster 3761 — 5y
0
It still will not work. I've removed an end) and also still wont. Thank you though. lukasdim -3 — 5y
0
Unless...Is this a local script? DeceptiveCaster 3761 — 5y
0
use Connect, also learn to indent LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Ah, it is actually good practice to not mix .Touched and a guitype's property together.

If you want to do this, I suggest getting more familar with RemoteEvents and Server to client and client to server capabilities. I would suggest learning those before attempting this, however, for the purpose of your question, I'll get down to explaining a fix.

For starters, insert a "RemoteEvent," into ReplicatedStorage, for the sake of this answer/little tutorial of mine, I may tweak the set up that I use to fit your specifications, as the set up I always use is one remote event and one remote function per game.

Name the remoteevent anything you want, I'll just keep it simple and go off, "Event," make sure your Event is in ReplicatedStorage though.

Now, let's start with the server side.

But before that, I want to state this is not the only method to set this up, you don't need a remote event, you could easily clone to the playergui and then the localscript will automatically run the code.

To the coding for the server side.

    workspace.Room.Door.Stuff.Touched:connect(function(hit) -- "workspace" is the same as game.Workspace, just shorter, either works however you see fit though.
    local player = game.Players:FindFirstChild(hit.Parent)
    if player then -- This sets it up so it checks if the part that touched the, "Stuff," in door is indeed a player.
    game.ReplicatedStorage.Event:FireClient(player) 
   end
end)

-- This will fire to, "player," which will automatically get the player that touched the part, one thing to learn is, both OnServerEvent which gets the server side of a FireServer() and FireClient() which fires from the server to the client, the first argument is ALWAYS the player, so for example. If I wanted to FireClient() to someone who joined a game just then, I'd only need to get the variable, or the default argument the PlayerAdded event gives us, same goes for the touched event. As long as the player argument is defined, it will fire to the SPECIFIC client in the first parameter, which is the player argument.

To the local side, you will want to create a localscript, anywhere is fine, but for the sake of making it simple, I'll put it in the frame that you are trying to change to visible.

local TweenService = game:GetService("TweenService") -- I suggest keeping this out of the event. Always put Services like these up at the top of the script.
local fadeBackground = script.Parent -- Once again, keep these up here. You could easily of set this to visible without needing to just define script.Parent again if you put this at the top of the script.

    game.ReplicatedStorage.Event.OnClientEvent:Connect(function()
            `script.Parent.Visible = true
              local tweenInfo = (
            3,
        Enum.EasingSty le.Sine,
        Enum.EasingDirection.Out,
        0,
        false,
        0
            )
            local tween = TweenService:Create(fadedBackground,tweenInfo,{BackgroundTransparency = 1})
            tween:Play()
    end)

I didn't go to in-depth on how you can possibly make a better fade gui, however, that is up to you to decide. I have shown you the a better way of creating a fading gui, as yours just won't work regardless in all honesty, you'd have to use Filtering Enabled to the extent it won't break, and you can't set a frame to false from a server script, and it's best to keep .Touched on server(I haven't tested it out on client, but I just know it'd be best to develop it on server, never felt the obligation to see it on client) So there you have it, I hope you enjoyed my extremely long tutorial.

0
Wow, that was a really in depth explanation. Thank you so much for teaching me this, as it is much needing in my game multiple times. One question though, does it matter where the server sided script is places in? lukasdim -3 — 5y
0
I would suggest putting all server side scripts somewhere in serverscriptservice, it's just my personal opinion on keeping things nice and organized. But you CANNOT put a server script inside of Replicated/Server storage and expct it to work without having it put somewhere inside of the game that will actually read the code. Unless it's a module, I believe requires are allowed in that case. Dev_Unreal 136 — 5y
Ad

Answer this question