the interface is just a square at the moment, but I want to make the script first and then play with the interface itself
Do you want the Gui object to be shown directly onto the userās screen? I am assuming that is the case since you have āGuiAbilitesā inside StarterGui
, like this:
yes, thatās what I want to do, if I touch a part, it will appear on my screen, if someone else touches that part, it will appear only on his screen
In that case you should do what I suggested earlier if you know how to do it. If you donāt then I can try and give you some guidance.
now Iām quite tired, I would need guidance, but I wouldnāt want to go and rest knowing that I canāt make a script
Unfortunately, we are not meant to give free scripts out to people, even though I would like to help. I would however, recommend doing some research yourself and finding something on Youtube
or the DevForum
for how to set one up.
Once youāve started trying and tell me what you are using and show the setup so far, I will be able to give you some guidance as to how to make it fully work if it doesnāt already do so. Hope this helps.
So like @FroDev1002 said, you donāt really understand, everything in startergui is replicated to the client in a folder called playergui, in this case your using a local script, so all you have to do is replace the abilityList variable to game.Players.LocalPlayer.PlayerGui.GuiAbilities
All credit goes to froDev she figured it out first.
- SCREENGUI in startergui
- localscript somewhere the client can access it (inside the ui, startergui, starterplayerscripts, startergear)
- Path to part
- what you already have
- make sure the screengui properties are right, cuz atp i feel like you made the frame invisible and not disabled the screengui
script structure
- VARIABLES
- path to part
- path to localplayer
- FUNCTION
- touched,
- if touched player == localplayer then
- LocalPlayer.PlayerGui:WaitForChild(āGUIā).Enabled = true
OR - LocalPlayer.PlayerGui:WaitForChild(āGuiā).Frame.Visible = true
I knew that, but to start with before @ElectroFLash_1 showed the state of the Explorer
menu, I wasnāt actually sure if āGuiAbilitiesā was an object that existed in PlayerGui
, since it would need to be placed in StarterGui for it to work.
Including this case, Iāve never seen a need to directly access PlayerGui
, because you would more often than not have the localscript
inside the actual ScreenGui
in the first place, so there would be no need to directly access it from game.Players.LocalPlayer.PlayerGui
in that way or context. Additionally, Iām saying including this case as well because I believe it was incorrectly implied that localscripts
could work from parts inside Workspace
, or at least when using .Touched
in this context which should be done on the server and not on the client I believe; at least in this case if nothing else.
Like I said Iāve never directly tried it with a localscript
before, but seeing that itās the use of the server side to complete such task and that I would usually do such a task on the server, I believe that you canāt directly access .Touched
from a part inside Workspace
if your using a localscript
instead of a script
. Correct me if wrong though.
Nvm most of it has been implemented already. Do you know how you make your ScreenGui
visible? Do you enable it through ScreenGui
or do you set visibility through another object inside of it? @ElectroFLash_1
This is a reminder, as to what it might look like for anybody who may not know.
Script:
local TouchPart = script.Parent --simplified the directory to not have to go through the whole of workspace
TouchPart.Touched:Connect(function(part) --get .Touched event from TouchPart (script.Parent)
if part.Parent:FindFirstChildWhichIsA("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(part.Parent) --should be game.Players:GetPlayerFromCharacter(part.Parent) not game.Players.GetPlayerFromCharacter(part.Parent)
if Player then
local ReplicatedStorage = game:GetService("ReplicatedStorage") --or optionally game.ReplicatedStorage
local RemoteEvent = ReplicatedStorage:FindFirstChild("ShowGui") --get RemoteEvent
RemoteEvent:FireClient(Player, Player) --pass the player as both 1st and 2nd when being sent to the client
print("fired!") --optional
end
end
end)
--most of code remains the same
Localscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:FindFirstChild("ShowGui")
local player = game.Players.LocalPlayer -- Get the local player
local GuiAbilities = script.Parent
GuiAbilities.Enabled = false --set to false when game is running
RemoteEvent.OnClientEvent:Connect(function(plrTouched)
print("fire detected") --optional
print("player:", plrTouched) --use is optional
if plrTouched then
if not GuiAbilities.Enabled then
GuiAbilities.Enabled = true
end
end
end)
--providing that you have some way to close the gui afterwards.
Once you step on the part, it should toggle the gui through the Remote Event
. Using one is negligible in this case for exploiters since all they can do is trigger the event for themselves without having to actually step on the part; itās not game-breaking or anything. This is only going to affect the exploiter and nobody else playing the game so you wonāt have to worry about that.
Just let me know if you donāt want to use that method of toggling whether the Gui is visible or not. It depends on whether you want to toggle the ScreenGui
ās visibility directly through .Enabled, or whether you want to set the visibility of another object inside of it using .Visible to toggle when it can be seen and when it canāt be. Iām also assuming that you have another way to make the Gui disappear if the user wants to click out of the āAbilityListā Screengui
.
If this worked for you, mark this post as solved.
This is what i was thinking, but as @FroDev1002 said, there is supposed to be another way. I cant explain because ive only done this with remote events
I know other people have given you some really great answers but heres my way of doing and iāll explain how it works
so, a remote event should be stored in replicated storage and you should name it something relevant to itās purpose. a remote event allows a server script and a local script to communicate. in your case, you want the server script to fire the event whenever your part is touched and the local script to open the UI. this is because UI is handled for each player individually, hence a local script!
Server Script in ServerScriptService:
local event = game.ReplicatedStorage.UIEvent --this is the event that will be fired
local thePart = game.Workspace.Touchpart --this is the part you want to touch to start the dialogue
local Debounce = false --this will be the cooldown
thePart.Touched:Connect(function(hit) --hit just means you can detect what hit the part and is the most effifient method
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum and Debounce == false then
Debounce = true
Event:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
wait(10) --this is how long your cooldown is, change it as needed
Debounce = false
end
end)
Now, to make the UI appear we use OnClientEvent
in our local script. The local script should be parented to the screen GUI, not the dialogue frame or textbox and definetely not StarterGUI itself
Local Script:
--this script is much shorter as we only need to see when the event is fired, and change the UI as needed
local Event = game.ReplicatedStorage.UIEvent --Your even name
local frame = script.Parent.Frame --Your frame name
Event.OnClientEvent:Connect(function() -- knows when the part is touched because we fired the event on the server ONLY when the part gets touched by a player
frame.Visible = true --makes your frame visible once the part is touched
end)
Hope you understand this way of doing it now, also let me know if it works!
I believe there isnāt another way, since localscripts
donāt run on Workspace objects and you need to include the localscript
inside the gui object whilst still being able to detect .Touched
on objects in Workspace. For that you need a script inside the object you want to detect and the localscript
inside the gui object that you want to show. You canāt have one localscript
achieving both results I donāt think.
Yeah, this is what i thought as well. Remote events have always been how iāve done things
Thatās similar to what but just layed it out differently; personal preference of course.
Edit:
Oops, sorry! i didnāt read your post and i was just putting my way and trying to explain things. i can delete it if you want
Up to you. I checked to make sure mine worked; Iām guessing you did the same thing.
Oops, sorry! i didnāt read your post and i was just putting my way and trying to explain things. i can delete it if you want
Yes, mine worked. Iāll leave it up if you donāt mind. Plus, if yours works better OP can just use thatā¦ Anyway, iām going to go, have a nice day!
Create a server script in this part, write this code and change RunContext to client
local Player = game.Players.LocalPlayer
local AbilityList = Player.PlayerGui:WaitForChild("GuiAbilities")
local TouchPart = script.Parent
TouchPart.Touched:Connect(function(part)
if part.Parent.Name == Player.Name then
AbilityList.Enabled = true
print("Work")
end
end)
it works, but can you explain more precisely how it works? to write down so that I know how to do in the future and to be able to shape the script according to my real requirements
for example I want to make you canāt move when you touch a part and I want to do more things, but I donāt want a script, I just want to understand how it works so I can understand how to do everything myself