So I’m trying to make this local script which allows you to buy weapons from a shop GUI via RemoteFunctions. This local script works fine until the “buy portion” of the script, where it fails to fire a RemoteFunction.
Now the odd thing is, the local script I am using for the RemoteFunction is a complete carbon copy of one I used in a completely different shop, which I specifically designed to be modular (essentially you can copy it into other shops using a similiar GUI and it will know exactly what to do). Which is what makes it weird.
Here's a short snippet from the local script:
– *** NOTE: I HAVE HID THE VARIABLES TO SIMPLIFY THE SCRIPT SO IT’S EASIER TO READ ***
success = nil
if selectedItem.Value ~= nil then -- (THIS HAS A VALUE)
success = RSFolder.CheckSale:InvokeServer(selectedItem.Value) -- script doesn't know what to do here and breaks as a result
print ("this doesn't print") -- This doesn't print out
end
And the full script...
local replicatedStorage = game:GetService("ReplicatedStorage")
local RSFolder = replicatedStorage:WaitForChild(script.Parent.Parent.Parent.Name)
local selectedItem = script.Parent.Parent.Parent:WaitForChild("SelectedItem")
local greenBackground = Color3.fromRGB(2, 234, 111)
local greenBorder = Color3.fromRGB(7, 53, 28)
local redBackground = Color3.fromHSV(234, 34, 2)
local redBorder = Color3.fromHSV(53, 28, 7)
local timeDelay = 2
local success
local canClick = true
-- Limitations
local Max = 5
local Starterpack = game.StarterPack
local Backpack = game.Players.LocalPlayer.Backpack
local Owned = script.Parent.Parent.Owned.Value
local Equipped = script.Parent.Parent.Equipped.Value
if Owned == true then
local Equipped = script.Parent.Parent.Equipped
if Equipped.Value == true then
script.Parent.Text = "Unequip"
else
script.Parent.Text = "Equip"
end
end
-- SOUNDS
local GUI = script.Parent.Parent.Parent.Parent
local Purchase = GUI.GUISounds.Purchased
local Equip = GUI.GUISounds.Equip
local Fail = GUI.GUISounds.Fail
local Both = game.ReplicatedStorage.Saving.Both
script.Parent.MouseButton1Click:Connect(function()
if canClick == true then
Both:FireServer()
-- OWNS ITEM
if Owned == true then
-- IF THE ITEM ISN'T EQUIPPED
if Equipped == false then
-- INVENTORY FULL
local equipsuccess = nil
if selectedItem.Value ~= nil then
equipsuccess = RSFolder.CheckSale:InvokeServer(selectedItem.Value)
end
if #Backpack:GetChildren() > 5 then
if Equipped == true then
Fail:Play()
RSFolder.Equip:InvokeServer(Equipped)
script.Parent.Text = ("Unequipped!")
canClick = false
script.Parent.BackgroundColor3 = greenBackground
script.Parent.BorderColor3 = greenBorder
script.Parent.TextColor3 = greenBorder
wait(timeDelay)
script.Parent.Text = ("Equip")
canClick = true
else
Equip:Play()
script.Parent.Text = ("Inventory Full!")
canClick = false
script.Parent.BackgroundColor3 = greenBackground
script.Parent.BorderColor3 = greenBorder
script.Parent.TextColor3 = greenBorder
wait(timeDelay)
script.Parent.Text = ("Unequip")
canClick = true
end
-- INVENTORY NOT FULL
else
if Equipped == true then
Equip:Play()
RSFolder.Equip:InvokeServer(Equipped)
script.Parent.Text = ("Equipped!")
canClick = false
script.Parent.BackgroundColor3 = greenBackground
script.Parent.BorderColor3 = greenBorder
script.Parent.TextColor3 = greenBorder
wait(timeDelay)
script.Parent.Text = ("Unequip")
canClick = true
else
Equip:Play()
RSFolder.Equip:InvokeServer(Equipped)
script.Parent.Text = ("Unequipped!")
canClick = false
script.Parent.BackgroundColor3 = greenBackground
script.Parent.BorderColor3 = greenBorder
script.Parent.TextColor3 = greenBorder
wait(timeDelay)
script.Parent.Text = ("Equip")
canClick = true
end
end
end
-- IF THE ITEM ISN'T OWNED
else
success = nil -- *** BUY PORTION BEGINS ***
if selectedItem.Value ~= nil then
success = RSFolder.CheckSale:InvokeServer(selectedItem.Value)
print ("this doesn't print")
end -- *** BUY PORTION ENDS***
-- CAN AFFORD ITEM
if success then
Purchase:Play()
canClick = false
script.Parent.BackgroundColor3 = greenBackground
script.Parent.BorderColor3 = greenBorder
script.Parent.TextColor3 = greenBorder
script.Parent.Text = ("Purchased!")
Owned = true
wait(timeDelay)
script.Parent.Text = ("Equip")
canClick = true
-- CAN'T AFFORD ITEM
else
Fail:Play()
canClick = false
script.Parent.BackgroundColor3 = redBackground
script.Parent.BorderColor3 = redBorder
script.Parent.TextColor3 = redBorder
script.Parent.Text = ("Can't Afford!")
Owned = false
wait (timeDelay)
canClick = true
script.Parent.BackgroundColor3 = greenBackground
script.Parent.BorderColor3 = greenBorder
script.Parent.TextColor3 = greenBorder
script.Parent.Text = ("Buy")
end
end
end
end)
What makes it even MORE weird, is the fact that I get absolutely no errors or warning in the output AT ALL, so I am essentially trying to repair this completely blindly.
What I would like to know is why this problem is occuring (for ONLY this script), and how I can attempt to repair it.