Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
I want it to disable so that the script would be easy, but how? Froredion 15 — 6y
0
I don't have filter enabled afterall. Froredion 15 — 6y
0
let me fix ur script :D itll be done in around 10 minutes mkay casper123123123 357 — 6y
0
That's the whole script, the error is from line 4 when I'm opening the game on roblox player. Froredion 15 — 6y
View all comments (5 more)
0
recheck my comment for a fixed version of ur script :D casper123123123 357 — 6y
0
This time, it isn't working even in roblox studio Froredion 15 — 6y
0
Did you look at my picture. casper123123123 357 — 6y
0
Has to be screengui > textbutton > script and in replicatedstorage the tool name GravityCoil. Works perfectly for me casper123123123 357 — 6y
0
did it work? casper123123123 357 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question