Hello! This is my first post.
I’m a beginner scripter, and was working on testing out different scripts to see how they would work.
I made a script that would open a small description box with information on the item clicked, then it allows you to purchase the item. I made a ServerScript inside of ServerScriptService that would respawn the item every 3 minutes, if it wasn’t currently inside of workspace. I’m not sure if this is relevant, but the script basically checks if there is certain text inside of a TextLabel before proceeding. Here’s my workspace:
Order of the scripts: The Purchase Script uses the Remote Event to fire the Open Menu local script, which makes the gui box visible. When the purchased button is clicked, the Script Buttons local script fire to the server, which takes away and adds values.
PurchaseScript:
function pressed(plr)
script.Parent.RemoteEvent:FireClient(plr)
script.Parent.ClientGame.OnServerEvent:connect(function(plr)
if plr:WaitForChild("Currency").Coins.Value >= 25 and plr:WaitForChild("PlayerGui").ShopGui.ShopTextFrame.TextValue.Text == "Apple" then
plr.Currency.Coins.Value -= 25
plr.Ingredients.Apple.Value += 5
script.Parent:Destroy()
end
end)
end
script.Parent.ClickDetector.MouseClick:connect(pressed)
OpenMenu Localscript:
local plr = game.Players.LocalPlayer
function receiveeventapple(play)
script.Parent.ShopTextFrame.Visible = true
script.Parent.ShopTextFrame.Description.Text = "A shipment of 5 apples. They probably found these on the ground, but they're being sold here, so obviously they have a purpose."
script.Parent.ShopTextFrame.Image.Image = "http://www.roblox.com/asset/?id=6436213195"
script.Parent.ShopTextFrame.PurchaseButton.Text = "Purchase for 25 Coins"
script.Parent.ShopTextFrame.TextValue.Text = "Apple"
end
workspace.AppleShipment.RemoteEvent.OnClientEvent:connect(receiveeventapple)
ScriptButtons Localscript:
local plr = game.Players.LocalPlayer
function gameing()
if script.Parent.ShopTextFrame.TextValue.Text == "Apple" then
workspace.AppleShipment.ClientGame:FireServer(plr)
script.Parent.ShopTextFrame.Visible = false
end
end
script.Parent.ShopTextFrame.PurchaseButton.Activated:connect(gameing)
RespawnScript:
bop = true
game.Players.PlayerAdded:connect(function(plr) --Store cargo respawn
repeat
wait(5)
print("game")
if workspace:FindFirstChild("AppleShipment") == nil then
local appleship = game.ServerStorage.Cargo.AppleShipment:Clone()
appleship.Parent = workspace
appleship.Position = Vector3.new(65, 11.2, 157.5)
end
until bop == false
end)
I know the code may be extremely sloppy, however it worked perfectly until it was cloned. If the solution involves rewriting the entirety of the code then I’m willing to do that. However, even if I don’t have to rewrite the entirety of the code, any criticism for my code would be great. Again, this is my first post, but I hope I included enough information to help find my solution. Thank you!
Edit: The respawn script was shortened to 5 seconds rather than 3 minutes for testing purposes.
Also, the gui is in the StarterGui service, and the Apple part is in workspace.