luarobloxluau

Proximity Prompt does not have errors but does not work


This may seem very easy but I am a beginner in scripting Roblox. There are no errors but the proximity prompt wasn't working. I tried to use the print function to test but it did not print either. Here is the code! (Also don't mind anything else)

local cost = 500
local serverscriptstorage = game.ServerScriptService
local petMoudle = require(game.ServerScriptService:WaitForChild("BasicEggModule"))
local prompt = workspace["Egg Holder"].Part.ProximityPrompt


prompt.Triggered:Connect(function (player)
    print("hi")
    if player.leaderstats.Cash.Value >= cost then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
        local pet = petMoudle.chooseRandomPet()
        local petval = Instance.new("StringValue")
        petval.Name = pet.Name
        petval.Parent = player.PetInventory
        print(pet.Name.." selected")
        game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
    end
end)

Thank you so much! Also, the script is in a folder in ServerScriptService.


Solution

  • I found out what the problem was! In the third line. It had to be ServerScriptService.Folder:WaitForChild().

    The Folder wasn't there.