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

The Clone in this script isn't working, and I dont have it in my backpack! Can you tell me why?

Asked by 5 years ago

Here is the script I marked where the clone was.

Player = game.Players.LocalPlayer
Item = script.Parent.Item
Guns = game.ReplicatedStorage.Guns
ItemCheck = game.ReplicatedStorage.Values.ItemsCheck
IC2 = game.ReplicatedStorage.Values.ItemsCheck2

script.Parent.MouseButton1Down:Connect(function(Clicked)
    while ItemCheck.Value == true do
        wait(0.1)
        if Item.Value == 0 then
            Item.Value = 1
        elseif Item.Value == 1 then
            if Player.Stats.Equip001 == true then
                Player.BackPack.Bruster.Parent = nil
                ItemCheck.Value = false
                IC2.Value = true
            elseif Player.Stats.Equip001 == false then
                local C001 = game.ReplicatedStorage.Guns.Bruster:Clone() -- Clone is here
                C001.Parent = Player.BackPack
                ItemCheck.Value = false
                IC2.Value = true
            end
        end
    end
end)

2 answers

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

Remember to use local VARIABLE in variables!

For first, you typed "BackPack" the correct is "Backpack" and for give with server You need to use RemoteEvent.

Example:


-- LOCAL SCRIPT -- local number1 = 500 local number2 = 1000 script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer(number1,number2) -- You can send variables/objects with :FireServer end) -- SERVER SCRIPT -- game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,var1,var2) -- Need to put "player"(or you can put "plr" anything. but need.), the var1 and var2 is variables that you send with :FireServer() print("I got your arguments, are: " .. var1 .. " and " .. var2 .. "!") end)

Is this a simple example. You can see more here: Roblox Wiki - RemoteEvents/Functions

For fix you code, need to change "BackPack" to "Backpack". And use RemoteEvents for give with the server.

And you forgot to put .Value in line 13 and 17

Now. create a RemoteEvent and put on ReplicatedStorage Create a Script(Server Script) and put in Workspace or ServerScriptService (ServerScriptService is the best.) and put this code:

local event = game.ReplicatedStorage.RemoteEvent -- Find event

event.OnServerEvent:Connect(function(plr,item_location,item_parent,argument) 
    if argument == "Destroy" then -- If argument is destroy, destroy item
        item_location.Parent = nil
    elseif argument == "New" then -- If argument is New clone a item
        item_location:Clone().Parent = item_parent
    end
end)

Now create a LocalScript and put on your button and put this code:

local Player = game.Players.LocalPlayer
local Item = script.Parent.Item
local Guns = game.ReplicatedStorage.Guns
local ItemCheck = game.ReplicatedStorage.Values.ItemsCheck
local IC2 = game.ReplicatedStorage.Values.ItemsCheck2

local event = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Down:Connect(function(Clicked)
    while ItemCheck.Value == true do
        wait(0.1)
        if Item.Value == 0 then
            Item.Value = 1
        elseif Item.Value == 1 then
            if Player.Stats.Equip001.Value == true then
                event:FireServer(Player.Backpack.Bruster,nil,"Destroy") -- Argument 1: Item, Argument 2: New parent of item, Argument 3: Destroy (Create: "New", Destroy: "Destroy")
                ItemCheck.Value = false
                IC2.Value = true
            elseif Player.Stats.Equip001.Value == false then
                event:FireServer(game.ReplicatedStorage.Guns.Bruster,Player.Backpack,"New") -- Argument 1: Item, Argument 2: New parent of item, Argument 3: New (Create: "New", Destroy: "Destroy")
                ItemCheck.Value = false
                IC2.Value = true
            end
        end
    end
end)

Hope it helped! :)

0
But how do I get the Exact player who clicked? MarkHasReset 77 — 5y
0
Oh nvm It worked except I Need to find a way to destroy it. MarkHasReset 77 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

try in a global script

Item = script.Parent.Item
Guns = game.ReplicatedStorage.Guns
ItemCheck = game.ReplicatedStorage.Values.ItemsCheck
IC2 = game.ReplicatedStorage.Values.ItemsCheck2

script.Parent.MouseButton1Down:Connect(function(Clicked)
    while ItemCheck.Value == true do
        wait(0.1)
        if Item.Value == 0 then
            Item.Value = 1
        elseif Item.Value == 1 then
            if Clicked.Stats.Equip001 == true then
                Clicked.BackPack.Bruster.Parent = nil
                ItemCheck.Value = false
                IC2.Value = true
            elseif Clicked.Stats.Equip001 == false then
                local C001 = game.ReplicatedStorage.Guns.Bruster:Clone() -- Clone is here
                C001.Parent = Player.BackPack
                ItemCheck.Value = false
                IC2.Value = true
            end
        end
    end
end)

The value 'Clicked' is the player who clicked, so it can be used instead of the player value + you can't use localPlayer in global scripts so 'Clicked' value is the only way, and in filtering enabled, some functions may not work unless accessed from server

Hope this helped fixing the problem :)

Answer this question