I have no idea whats going on here. Everything should be working fine but its not.
Server Script in ServerScriptService:
local replicatedStorage = game:GetService("ReplicatedStorage")
local opengui = replicatedStorage:WaitForChild("OpenGui")
workspace:WaitForChild("ShopPrompt"):WaitForChild("ProximityPrompt").Triggered:Connect(function(player)
print('pls')
opengui:FireClient(player)
end)
Local Script In StarterGui:
local replicatedstorage = game:GetService('ReplicatedStorage')
local opengui = replicatedstorage:WaitForChild('OpenGui')
opengui.OnClientEvent:Connect(function()
print('yo why this no work')
script.Parent.Enabled = true
end)
-- server
local replicatedStorage = game:GetService("ReplicatedStorage")
local opengui = replicatedStorage:WaitForChild("OpenGui")
print("Server is running")
workspace:WaitForChild("ShopPrompt"):WaitForChild("ProximityPrompt").Triggered:Connect(function(player)
print('preparing to fire event')
opengui:FireClient(player)
print('fired event!')
end)
-- client
local replicatedstorage = game:GetService('ReplicatedStorage')
local opengui = replicatedstorage:WaitForChild('OpenGui')
print("client is running")
opengui.OnClientEvent:Connect(function()
print("received event")
script.Parent.Enabled = true
end)
Just to make sure that the client is actually running.
oh yeah, just saw the timestamp, an alternative for remote events is for the client to listen for when the proximity prompt is pressed, but I don’t know why the remoteEvent isn’t working.
It’s a gui, I think I might of had problems with the parent not being enabled. But For reference for now I’ll send the entire script to check for errors.
local Debris = game:GetService("Debris")
local localplayer = game.Players.LocalPlayer
local replicatedstorage = game:GetService('ReplicatedStorage')
local opengui = replicatedstorage:WaitForChild('OpenGui')
local forcefieldremote = replicatedstorage.DestroyForceField
print("client is running")
function forcefield(Target)
local FF = Instance.new("ForceField")
FF.Parent = Target.Character
FF.Name = 'ForceField69'
Debris:AddItem(FF, 69420)
end
while wait(1) do
if script.Parent.Enabled == true and localplayer.Character:FindFirstChild('ForceField69') == nil then
forcefield(localplayer)
wait(0.001)
end
if script.Parent.Enabled == true and localplayer.Character:FindFirstChild('ForceField69') == nil then
forcefieldremote:FireServer()
wait(0.001)
end
end
opengui.OnClientEvent:Connect(function()
print('yo why this no work')
script.Parent.Enabled = true
end)
may i ask why you’re sending a remote to open a gui? It seems by your code that the gui is already created, so why not just get the prompt triggered on the client and open the gui using the client script. This would not only make it easier but it would also prevent opening the gui being delayed if the person has network issues
You might need the LocalScript’s parent to be enabled for the script to handle events, try moving it into StarterGui and re-adjusting the code for that.
Replicated/Functioned fine for me. The problem probably lies in something not mentioned; check your testing method to make sure the result you’re looking for (UI enabling) actually behaves how you want if you just set the property manually in studio.
Ok this is the most viable answer so I will make sure to test this in a moment. The only other problem is that there is an error with firing or an error in the local script causing it not to work
wouldn’t it be easier to use one local script that handles all proximity triggers then using attributes to find the gui to show. You could do something like
local pps = game.ProximityPromptService
local localPlayer = game.Players.LocalPlayer
pps.PromptTriggered:Connect(prompt)
local gts = prompt:GetAttribute("GuiToShow")
if gts then
local ui = localPlayer.PlayerGui[gts]
ui.Enabled = not ui.Enabled
end
end)
of course you’ll have to add an attribute to the proximity prompt named “GuiToShow” with the value set to the name of the gui you want to open for this to work
You need to connect the event before the loop, if you have an infinite loop then the code after it will never run.
Reorganize it.
opengui.OnClientEvent:Connect(function()
print('yo why this no work')
script.Parent.Enabled = true
end)
while wait(1) do
if script.Parent.Enabled == true and localplayer.Character:FindFirstChild('ForceField69') == nil then
forcefield(localplayer)
wait(0.001)
end
if script.Parent.Enabled == true and localplayer.Character:FindFirstChild('ForceField69') == nil then
forcefieldremote:FireServer()
wait(0.001)
end
end