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
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()
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.
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)
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
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?
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.
its fine, but what i do, is first go to you search bar and type in “remove” and then something should pop up and then find roblox
i don’t know if you have mac or windows computer, but i think you got a windows computer