What do I want to achieve?
I want to make it so that it fires a remote event to the client once the player triggers the Proximity Prompt.
What is the issue?
It works the first time, the remote event was successfully fired and received, but when trying to trigger the proximity prompt a second time, it ceases to work.
VIDEO
3. What solutions have I tried so far?
Here’s some code
local prompt = script.Parent
local rs = game:GetService("ReplicatedStorage")
local events = rs:WaitForChild("Remotes"):WaitForChild("Events")
local pie = events:WaitForChild("PlayerShopInteraction")
prompt.Triggered:Connect(function(plr)
pie:FireClient(plr)
local chr = plr.Character or plr.CharacterAdded:Wait()
local hum = chr:FindFirstChildWhichIsA("Humanoid")
hum.WalkSpeed = 0
hum.JumpPower = 0
prompt.Enabled = false
wait(10)
prompt.Enabled = true
end)
and below is the client one:
local rs = game:GetService("ReplicatedStorage")
local events = rs:WaitForChild("Remotes"):WaitForChild("Events")
local pie = events:WaitForChild("PlayerShopInteraction")
pie.OnClientEvent:Connect(function(shopname, itemnum, Items, Prices, ID, Desc, Rarity)
-- These tables were defined but the part where it's defined were not shown.
print("Received package from server to setup.")
ui:WaitForChild("Background").Visible = false
print("it works!")
ui:WaitForChild("Background").Visible = true
pie = events:WaitForChild("PlayerShopInteraction")
end)
However, the player’s speed & jump power were set to 0 after the prompt was triggered in both attempts (as I was unable to move) and the code ran without any exception, error, or warnings. It’s just that there was no output in the second attempt.
The UI variable is connected to a ScreenGui. If that has errors the compiler will throw an exception, which I explained that there was not any of those.
Well I see your issue straight away, you’re firing the client without transmitting any data to the client from the server but on the client’s side your expecting to receive data for the following parameters.
The following code snippet includes comments which should give further incite into how RemoteEvent instances should be used.
pie:FireClient(player, ...) --additional arguments after the player instance (which specifies which client to fire) are transmitted to the fired client
pie.OnClientEvent:Connect(function(...) --parameters are received by the callback function connected to the event in order to handle the data (values) which have been sent by the server