Randomized Tool Giver Not Working (ProximityPrompt)

Hello everyone! I’m new to scripting; however, I’m so excited to learn and become better!

  1. What do you want to achieve?
    I’d like to create a proximityprompt that 1. triggers the RemoveEvent “TakeCash” 2. Gives the player a tool that is randomized (and prevents duplicates from being given). 3. Has a wait time before being given the tool (10 seconds) after proximityprompt is triggered.

  2. What is the issue?
    “TakeCash” is not being triggered (RemoteEvent is in Replicated storage and its function is in ServerScripts) and the player isn’t even being given a tool when the Prox.Prompt is triggered.

  3. What solutions have you tried so far?
    I’ve tried re-writing the code (from the very limited knowledge I have) as well as searching for hours on Reddit, the DevForum, and other resources. I’ve also tried putting the tools in both ReplicatedStorage and ServerStorage; however, both times were unsuccessful.

Here’s my code/script:

local ProxPromp = script.Parent.ProximityPrompt

ProxPromp.Triggered:Connect(function (Player)
	local tool = script.Parent:FindFirstChild("Value"..math.random(1,6))
	local clone = tool.Value:Clone()
	
	game.ReplicatedStorage.TakeCash:FireServer()
	wait(0.1)
	
	wait (10) 
	clone.Parent = Player.Backpack
	
end)

and here’s a screenshot (to show the Explorer):

Each tool is connected to an ObjectValue.
Please let me know if I can provide you with any additional information—I truly appreciate the help! :grinning:

You’re trying to FireServer on the server (this is what’s stopping the script). You can only do this on the client. But an alternative would be using BindableEvents.

You can fire it using: game.ReplicatedStorage.TakeCash:Fire(Player)

Instead of .OnServerEvent, you use .Event.

BindableEvents allow communication between the same side of the game. For example: server-server or client-client. You can look more into BindableEvents: here


If you had no understanding of what I meant, delete the TakeCash RemoteEvent and change it to a BindableEvent. Connect your function to .Event instead of .OnServerEvent (since everything is going through the server).

For the ProximityPrompt Script, it would look like this:

ProximityPrompt Script
local ProxPromp = script.Parent.ProximityPrompt

ProxPromp.Triggered:Connect(function (Player)
	local tool = script.Parent:FindFirstChild("Value"..math.random(1,6))
	local clone = tool.Value:Clone()
	
	game.ReplicatedStorage.TakeCash:Fire(Player)
	wait(0.1)
	
	wait (10) 
	clone.Parent = Player.Backpack
	
end)

The TakeCash script would look something like this:

TakeCash script
game.ReplicatedStorage.TakeCash.Event:Connect(function(Player) -- The Player parameter is not here by default, it was just passed by the :Fire function from the ProximityPrompt script
    -- Run whatever you want
end)

Also, next time… Make sure to check the output for errors. It’s really helpful and can save you a lot of time:
image

1 Like

Wow! Thank you so much, I am blown away by how thoughtful your response was and how useful the information you’ve provided me is!

Everything now works perfectly :slight_smile: you’ve been extremely helpful! I will look more into BindingEvents, thank you for the recommendation.