✓ Accepted answer
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 number1 = 500
local number2 = 1000
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer(number1,number2)
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,var1,var2)
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
event.OnServerEvent:Connect(function(plr,item_location,item_parent,argument)
if argument == "Destroy" then
item_location.Parent = nil
elseif argument == "New" then
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")
ItemCheck.Value = false
IC2.Value = true
elseif Player.Stats.Equip001.Value == false then
event:FireServer(game.ReplicatedStorage.Guns.Bruster,Player.Backpack,"New")
ItemCheck.Value = false
IC2.Value = true
end
end
end
end)
Hope it helped! :)
2 comments
But how do I get the Exact player who clicked?
Oh nvm It worked except I Need to find a way to destroy it.