Help With Remote Events

I have a script that plays an animation after a proximity prompt is triggered and the play clicks a button on a gui that is activated by the prompt. The script is supposed to know when the button is pressed by the gui becoming not visible, but this change happens on the client side, so as far as the server is concerned, the gui is still visible. I want to use a RemoteEvent, but I don’t know how to do this because I want many objects being animated all under the same name, and I don’t want them all to play the animation after the prompt is triggered. Here is the script:

local fridgePromt = script.Parent.MiddleShelf.FridgePrompt

local animator = script.Parent.FridgeCore.AnimationController.Animator
local openAnimation = script.Parent.FridgeCore.Animations.DoorOpen
local openAnimTrack = animator:LoadAnimation(openAnimation)

local closeAnimation = script.Parent.FridgeCore.Animations.DoorClose
local closeAnimTrack = animator:LoadAnimation(closeAnimation)

fridgePromt.Triggered:Connect(function(plr)
	local PlayerGui = plr:WaitForChild("PlayerGui")
	wait(0.3)
	local fridgeGui = PlayerGui.FridgeGUI.FridgeGUIFrame
	while fridgeGui.Visible == true do
		wait(0.3)
	end
	openAnimTrack:Play()
	wait(0.5)
	closeAnimTrack:Play()
end)

This is a continuation of another topic, but I felt this needed its own topic because it was very different from the original issue. Here is the topic: https://devforum.roblox.com/t/animations-not-playing/1719594/11

4 Likes
  1. Use task.wait() instead of wait() --it’s more accurate and better, wait is deprecated.
  2. So your issue is that you want to close the UI from the server?
1 Like

Sorry for not elaborating. The gui is being opened from the server and closed from the client. The code:

while fridgeGui.Visible == true do
   wait(0.3)
end

is waiting for it to be closed. This script is on the server side, and the gui is being closed client side, so the server never sees that the gui is closed. Therefore, this code will wait forever, and nothing will happen, and this is the problem I’m trying to fix.

wait so you have a proximity prompt and a separate gui on the client, and the player has to press both of them? is that correct?

The proximity prompt is on the server, there is a separate gui on the client, and the player triggers the proximity prompt. When it is triggered, the server opens the separate gui on the client. Then, the player presses a text button, so the client closes the gui on the client.

1 Like

ohhh, makes much more sense,
let me reiterate what you mean
so basically,

first, player activates proximity prompt
second, a gui pops up for the player client
and third, player presses the button on the gui and there’s a remote event that fires from the client to the server
then, the server waits until it receives the event and finally it plays the animation

is that correct?

1 Like

i think instead checking under the proximity prompt function, couldn’t you use something on the server side to receive the fired remote event, instead of using a while loop to check for visible property change?

server sided function

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote_event = ReplicatedStorage:WaitForChild("RemoteEvent")

local function playAnimation()
openAnim:Play()
openAnimation.Stopped:Wait()
closeAnim:Play()
end

remote_event.OnServerEvent:Connect(playAnimation)

client sided fire event

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local remote_event = ReplicatedStorage:WaitForChild("RemoteEvent")
 
-- Fire the remote event
remote_event:FireServer()

Yes, that’s what I want to happen.

1 Like

Great code, but there’s one problem. It is a fridge in a restaurant, so I want to replicate it many times, and I don’t want to have to go in a change the code each time, so I don’t know what to do.

1 Like

yeah i got one solution for you,
the tag editor plugin

if you need help using it, just ask me, but basically you can keep all your code in one script

1 Like

Thank you for the suggestion. I have many applications for my game and I am very excited to use it, but I’m not sure how it could help me. Could you please elaborate on your solution?

When you say replicate it multiple times, are you referring to there being multiple fridges, and you would like all of them to have this effect? Also I’d recommend keeping all UI stuff client sided, it helps in the long run. Here is a proposed solution you could, in theory use. If you’re looking to have the animation on the client side, have you thought of TweenService? It might be easier then firing a remote
to activate that fridge.

Keep in mind for this to work, use the Tag Editor plugin as shown above. Click on the plugin, press “Create new tag”, name it “Fridge”, and while you have “Fridge” selected, select all of the fridges in your game.

-- client
local CollectionService = game:GetService("CollectionService")
local Fridges = CollectionService:GetTagged("Fridge")
local fridgeGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("FridgeGUI")

local selectedFridge 


for _, fridge in pairs(Fridges) do 
	fridge.ProximityPrompt.Triggered:Connect(function(plr)
		if plr == game.Players.LocalPlayer then
		selectedFridge = fridge
			fridgeGui.FridgeGUIFrame.Visible = true
		end
	end)
end

-- at this point, i assume the gui is probably closed by pressing a button. change this to the name of the button.

fridgeGui.FridgeGUIFrame.Close.MouseButton1Click:Connect(function()
	fridgeGui.FridgeGUIFrame.Visible = false
	game.ReplicatedStorage.RemoteEvent:FireServer(selectedFridge)
end)
-- server
local function AnimateFridge(plr, Fridge)
	local animator = Fridge.AnimationController.Animator
	local openAnimation = Fridge.Animations.DoorOpen
	local closeAnimation = Fridge.Animations.DoorClose
	
	
	local openAnimTrack = animator:LoadAnimation(openAnimation)
	wait(0.5)
	local closeAnimTrack = animator:LoadAnimation(closeAnimation)
	
end


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(AnimateFridge)
2 Likes

i think what they mean, is they want them to all be functional, but without having to use multiple scripts for each of them

2 Likes

alright, i’ll try my best to explain how to use collection service/tag editor plugin

so first, get the plugin (tag editor plugin),
next go to the plugin tab,
and then click on manage plugins,
image
and on the new tab scroll down until you find the tag editor plugin and click on the slider to turn it on


and then on the plugin tab, you should see the plugin, and click on both of the images
image
then there should be another tab that pops up
and then add new tag, make sure you name it accordingly, for your case i would name it “fridge”
image
click on your model and then press on the check box to tag it

and tag all the models you need to, and thats pretty much all the steps to using it

then add a script, if you doing server then preferably in server script service unless its on the client then either add it to starter gui or the start player/character scripts, it kinda depends what you’re going for

local CollectionService = game:GetService("CollectionService")
local Fridges = CollectionService:GetTagged("Fridge")

for _, fridge in pairs(Fridges) do 
--code here
end
1 Like

also here’s a testing place if you want to see the tag editor in the process
teleport_place.rbxl (76.9 KB)

1 Like

Do I put the client script in starter player scripts? Also, there are a lot of buttons within the gui that can close the gui, so how would I modify it to allow any button to close it?

probably in starter gui since you’re doing something with the gui

1 Like

I put those scripts in StarterPlayerScripts, because it wasn’t working in StarterGui, but now the game won’t load because it says there is an error loading core scripts: no verified patch could be loaded.

thats strang, i think its probably roblox is broken

Maybe, I’ll try tomorrow and reply back to say if its working.