-
I’m trying to enable the GUI upon player join, and turn on the sound when the ONButton
is clicked, and the sound should stop when the OFFButton
is clicked, I want these sounds to be played LOCALLY!
-
The UI simply doesn’t show up.
ServerScript in ServerScriptService
local RemoteEvent = game.ReplicatedStorage.VaccumEvent
local ONButton = game.StarterGui.VaccumUI.CleaningGUI.CleaningFrame1.ONButton
local cleaninggui = game.StarterGui.VaccumUI.CleaningGUI
local tool = game.StarterPack["Vaccum Cleaner"]
tool.Equipped:Connect(function()
cleaninggui.Visible = true
cleaninggui.Parent = true
end)
ONButton.MouseButton1Click:Connect(function()
RemoteEvent:FireClient()
end)
LocalScript in StarterPlayerScripts
local RemoteEvent = game.ReplicatedStorage.VaccumEvent
local sound = game.StarterPack["Vaccum Cleaner"].Sound
RemoteEvent.OnClientEvent:Connect(function()
sound:Play()
end)
Thank you, please try and explain so I can understand!
Okay both scripts need reworking.
first script, you should put the server script inside the tool and do these changes:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local tool = script.Parent
tool.Equipped:Connect(function()
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if player then
RemoteEvent:FireClient(player, "ShowGUI")
end
end)
and for the local script, you should keep it anywhere in client enviroment, and do these changes:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local player = game.Players.LocalPlayer
local sound = player:WaitForChild("Backpack"):WaitForChild("Vaccum Cleaner").Sound
RemoteEvent.OnClientEvent:Connect(function(action)
if action == "ShowGUI" then
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
cleaninggui.Visible = true
end
end)
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
local ONButton = cleaninggui.CleaningFrame1.ONButton
local OFFButton = cleaninggui.CleaningFrame1.OFFButton
ONButton.MouseButton1Click:Connect(function()
sound:Play()
end)
OFFButton.MouseButton1Click:Connect(function()
sound:Stop()
end)
Hi, doesn’t work. I followed all instructions you provided me, and the warning showing is:
nfinite yield possible on 'Players.wispofficial.Backpack:WaitForChild("VCleaner")'
You probably mistyped the name of the tool. copy my scripts and see if they work.
Still nothing, i did everything correctly and the same Infinite Yield is still showing/.
Can you show both scripts and tell me what you did exactly, and where are the scripts located?
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local tool = script.Parent
tool.Equipped:Connect(function()
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if player then
RemoteEvent:FireClient(player, "ShowGUI")
end
end)
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local player = game.Players.LocalPlayer
local sound = player:WaitForChild("Backpack"):WaitForChild("Vaccum Cleaner").Sound
RemoteEvent.OnClientEvent:Connect(function(action)
if action == "ShowGUI" then
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
cleaninggui.Visible = true
end
end)
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
local ONButton = cleaninggui.CleaningFrame1.ONButton
local OFFButton = cleaninggui.CleaningFrame1.OFFButton
ONButton.MouseButton1Click:Connect(function()
sound:Play()
end)
OFFButton.MouseButton1Click:Connect(function()
sound:Stop()
end)
Can you show replicated storage?
There is nothing wrong, let’s add some debugging then:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local tool = script.Parent
tool.Equipped:Connect(function()
print("Tool Equipped")
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if player then
RemoteEvent:FireClient(player, "ShowGUI")
print("Player Exists and fired to client")
end
end)
Client:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local player = game.Players.LocalPlayer
local sound = player:WaitForChild("Backpack"):WaitForChild("Vaccum Cleaner").Sound
print("Script is running")
RemoteEvent.OnClientEvent:Connect(function(action)
print("Recieved Event")
if action == "ShowGUI" then
print("Conditon correct")
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
cleaninggui.Visible = true
end
end)
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
local ONButton = cleaninggui.CleaningFrame1.ONButton
local OFFButton = cleaninggui.CleaningFrame1.OFFButton
ONButton.MouseButton1Click:Connect(function()
sound:Play()
end)
OFFButton.MouseButton1Click:Connect(function()
sound:Stop()
end)
Okay move the local script to inside the tool and change the script to this:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local player = game.Players.LocalPlayer
local tool = script.Parent
local sound = tool:WaitForChild("Sound")
print("Script is running")
RemoteEvent.OnClientEvent:Connect(function(action)
print("Received Event")
if action == "ShowGUI" then
print("Condition correct")
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
cleaninggui.Visible = true
end
end)
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
local ONButton = cleaninggui.CleaningFrame1.ONButton
local OFFButton = cleaninggui.CleaningFrame1.OFFButton
ONButton.MouseButton1Click:Connect(function()
sound:Play()
end)
OFFButton.MouseButton1Click:Connect(function()
sound:Stop()
end)
OnClientEvent can only be used on the client
Man i said move the local script to inside the tool, so you have 2 scripts inside the tool (server and local)
This setup should fix the bugs.
So the LocalScript remains this?
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local tool = script.Parent
tool.Equipped:Connect(function()
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if player then
RemoteEvent:FireClient(player, "ShowGUI")
end
end)
Server:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local tool = script.Parent
tool.Equipped:Connect(function()
local player = game.Players:GetPlayerFromCharacter(tool.Parent)
if player then
RemoteEvent:FireClient(player, "ShowGUI")
end
end)
Local Script:
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated:WaitForChild("VaccumEvent")
local player = game.Players.LocalPlayer
local tool = script.Parent
local sound = tool:WaitForChild("Sound")
print("Script is running")
RemoteEvent.OnClientEvent:Connect(function(action)
print("Received Event")
if action == "ShowGUI" then
print("Condition correct")
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
cleaninggui.Visible = true
end
end)
local cleaninggui = player:WaitForChild("PlayerGui"):WaitForChild("VaccumUI").CleaningGUI
local ONButton = cleaninggui.CleaningFrame1.ONButton
local OFFButton = cleaninggui.CleaningFrame1.OFFButton
ONButton.MouseButton1Click:Connect(function()
sound:Play()
end)
OFFButton.MouseButton1Click:Connect(function()
sound:Stop()
end)
it works, let me test wiht two clients!
1 Like