Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why it doesn't give me the item when I buy it?

It isn't giving me the item when I buy it on the roblox server, but in roblox studio, it is giving me the item. Here's the script:

local p = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:connect(function()
	if p.Backpack:FindFirstChild("GravityCoil") or p.StarterGear:FindFirstChild("GravityCoil") or game.Workspace[p.Name]:FindFirstChild("Backpack") then
		script.Parent.Parent.YoruPrice.Text = "You already brought this item!"
		wait(5)
		script.Parent.Parent.YoruPrice.Text = "    Gravity Coil - 1,000"

else
	if p.leaderstats.Cash.Value >= 1000 then
			replicatedstorage.Yoru:Clone().Parent = p.Backpack
			replicatedstorage.Yoru:Clone().Parent = p.StarterGear
			p.leaderstats.Cash.Value = p.leaderstats.Cash.Value - 1000
	else
	 local cashrequirement = 1000 - p.leaderstats.Cash.Value
		script.Parent.Parent.YoruPrice.Text = "You need " ..cashrequirement.. " more money to buy this item!"
		wait(5)
		script.Parent.Parent.YoruPrice.Text = "    Yoru - 1,000"
		end
	end
end)

2 answers

I redid the entire script. To make it more sleek and cleaner. Anyways here it is also a image on how i set it up in studio

-- Variables

local player = script.Parent.Parent.Parent.Parent
local character = game.Workspace:WaitForChild(player.Name)
local replicatedstorage = game:GetService("ReplicatedStorage")
local missingcash = 0
local price = 1000
-- Functions
script.Parent.MouseButton1Click:connect(function()
	
	-- Check if player already owns item
    if player.Backpack:FindFirstChild("GravityCoil") or character:FindFirstChild("GravityCoil") or player.StarterGear:findFirstChild("GravityCoil") then
        script.Parent.Text = "You already own this item!"
        wait(5)
        script.Parent.Text = "    Gravity Coil - 1,000"
else
	if player.leaderstats.Cash.Value >= price then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
		local gear = replicatedstorage.GravityCoil:Clone()
		gear.Parent = player.Backpack
		local startergear = replicatedstorage.GravityCoil:Clone()
		startergear.Parent = player.StarterGear
	else
		missingcash = price - player.leaderstats.Cash.Value
		script.Parent.Text = "You need " ..missingcash.. " more money to buy this item!"
		wait(5)
		script.Parent.Text = "Price | ".. price
	end
end
end)

http://prntscr.com/ivxn34

9 comments

0

I want it to disable so that the script would be easy, but how?

0

I don't have filter enabled afterall.

0

let me fix ur script :D itll be done in around 10 minutes mkay

0

That's the whole script, the error is from line 4 when I'm opening the game on roblox player.

0

recheck my comment for a fixed version of ur script :D

0

This time, it isn't working even in roblox studio

0

Did you look at my picture.

0

Has to be screengui > textbutton > script and in replicatedstorage the tool name GravityCoil. Works perfectly for me

0

did it work?

I just fixed it myself, the problem is, I didn't use for loops.

This discussion is preserved as it was. New answers, comments, and votes are closed.