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

Why cant my script find this item in replicated Storage?

Asked by 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
game.Players.PlayerAdded:Connect(function(player)
print(player.Name..("Has Joined"))
local ReplicatedStorage= game:GetService("ReplicatedStorage")
local Buy = player.PlayerGui:WaitForChild("Gui").Main.PromptPurchase.Purchase
local Cash = player:WaitForChild("leaderstats").Cash
local Price = Buy.Parent.ItemPrice
local Name = Buy.Parent.ItemName
local GunItemName = game:GetService("ReplicatedStorage").GunItemName --GunItemName is a stringValue in ReplicatedStorage.
local clonegun = ReplicatedStorage.Guns:FindFirstChild(GunItemName.Value)
Buy.MouseButton1Click:Connect(function()
    if Cash.Value >= Price.Value then
        Cash.Value = Cash.Value - Price.Value
        print(GunItemName.Value)
        print("Bought")
        clonegun:Clone().Parent = player.Backpack -- im getting a error that says "clonegun' (a nil value)"
        print("Cloned")
        end
    end)
end)

2 answers

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

We've been talking in the chat feature, I'm just posting here to show you some formatting

--Create a RemoteEvent in ReplicatedStorage, title it what you want
--Server side
local PurchaseGun = game:GetService("ReplicatedStorage").EventName

--Add guns and change prices as you wish.

local GunPrices = {
    ["Pistol"] = 100,
    ["Revolver"] = 200,
    ["Uzi"] = 300
}

PurchaseGun.OnServerEvent:Connect(function(Player, GunName)
local Cash = Player:FindFirstChild("leaderstats").Cash
    if Cash.Value >= GunPrices[GunName] then
        Cash.Value = Cash.Value - GunPrices[GunName] 
        print(GunName)
        print("Bought")
    local clonegun = ReplicatedStorage.Guns:FindFirstChild(GunName)
        clonegun:Clone().Parent = Player.Backpack -- im getting a error that says "clonegun' (a nil value)"
        print("Cloned")
        end
    end)
end)

Then in a LocalScript, parented to the GUI

local PurchaseGun = game:GetService("ReplicatedStorage").EventName
local Buy = script.Parent.BuyButton --Obviously, change this to the location of the button
local Gun = "DefaultGun"

Buy.MouseButton1Click:Connect(function()
    PurchaseGun:FireServer(Gun)
end)

--I am assuming the player uses a GUI to choose the gun type?  In that case, you need to add functions for whatever buttons you are using to choose.  For example,

local RevolverButton = script.Parent.RevolverButton --Change location as needed
RevolverButton.MouseButton1Click:Connect(function()
    Gun = "Revolver"
end)

--If you want the player to just press the gun button, as in the Player presses "revolver" and it attempts to buy the revolver,

local RevolverButton = script.Parent.RevolverButton --Change location as needed
RevolverButton.MouseButton1Click:Connect(function()
    PurchaseGun:FireServer("Revolver")
end)
--This would get rid of the BuyButton function, but you would need to create one of these for every gun.

Any questions, just ask

0
ok GunzerkingBeast21 -4 — 5y
0
Omg Thankyou dude It worked You have no idea how much of a help this was GunzerkingBeast21 -4 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

line 9 should be

local clonegun = ReplicatedStorage.Guns:FindFirstChild("GunItemName").Value
0
It shouldn't. As GunItemName is a StringValue, as you can see on line 8. RubenKan 3615 — 5y
0
well you need "" User#28169 0 — 5y
0
Does it need to be a value? GunzerkingBeast21 -4 — 5y
0
i think? User#28169 0 — 5y

Answer this question