I need help trying to open a Gui using a proximity prompt and a Remote Event.
Whenever I trigger the proximity prompt it says that the argument must be a player object
I can’t find anything on the forums so if anyone can assist me in this matter that would be helpful
This is my Server Script that is connected to the Proximity Prompt:
local pp = script.Parent
local rs = game:GetService("ReplicatedStorage")
local REEvent = rs.Events.RemoteEvent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
pp.Triggered:Connect(function()
REEvent:FireClient(player)
end)
And this is my Local Script connected to StarterCharacterScripts:
local rs = game:GetService("ReplicatedStorage")
local PlayerService = game:GetService("Players")
local localPlayer = PlayerService.LocalPlayer
local event = rs.Events.RemoteEvent
event.OnClientEvent:Connect(function()
localPlayer.PlayerGui.CardGameGui.Enabled = true
task.wait(0.5)
end)
A proximity prompt cannot be triggered without a player, and when a player triggers it, Roblox returns the player object. If it doesn’t, that is an issue that should be reported. Therefore, there is no need to perform a type check on this argument, as it should always be of a single, expected class.
We could also ask for proof, have you ever seen a RBXScriptSignal or a Roblox API returning an argument other than the guaranteed and expected classtype as specified on the engine and documentation?
Is also a string but script analisis in runtime could say otherwise as far as i know so no your argument is not valid when speaking of AOT compilation part likely it needs further argumentation with disecting disasembled code
I recommend you read the Luau documentation, this is out of the scope of OP’s discussion, and if you are still unsure after I explain it here, I invite you to create another post in Scripting Support.
Roblox has already made the type annotation to the things being sent through that Triggered Signal, there is no need to double annotate. Internally, the .Triggered signal has these predefined return types:
And as you can see, even if I didn’t define “p” as “Player”, the method :Kick() still comes up, proving that there is no need to annotate this variable.
i was talking about actual typechecking part as to how this example would behave in native mode and if assembly of 2 different examples would be the same;
Not about type anotations.
Hi, it’s common for beginners to use LocalPlayer in a Script, which is not possible. Fortunately, the player is passed as a parameter of the Triggered event (see docs), so you can just do this:
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage.Events.RemoteEvent
script.Parent.Triggered:Connect(function(player)
event:FireClient(player)
end)
That is the fix to your issue. However, it is possible to use the Triggered event on the client aswell, so you can just merge your code into your LocalScript like this:
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local proximityPrompt = workspace.Part.ProximityPrompt -- Change this path to point to where your ProximityPrompt is
script.Parent.Triggered:Connect(function(player)
playerGui.CardGameGui.Enabled = true
end)
Your gui should appear nicely when the ProximtyPrompt is triggered, but the code could be even better.
From the years I’ve been scripting, I never really had to enable or disable ScreenGuis directly. It would be better to change the Visible property of the objects inside.
Here is that same LocalScript code from above parented to the ScreenGui, which detects when the ProximityPrompt is triggered and makes a frame named “Frame” in the ScreenGui visible.
local proximityPrompt = workspace.Part.ProximityPrompt -- Change this path to point to where your ProximityPrompt is
script.Parent.Triggered:Connect(function(player)
script.Parent.Frame.Visible = true
end)
Your explorer heirarchy should look like this, and the code above goes inside the LocalScript.