Hello, im having problems with value appearing in someone elses inventory
game.ReplicatedStorage.ServerStats.TwitterCode.OnServerEvent:connect(function(Player,Code)
if Code == “Gift” then
local CodesFolder = game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name).Codes
if game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name).Codes:FindFirstChild(“Gift”) == nil then
print(“Gift not found in playerstats”)
local NewCodes = Instance.new(“BoolValue”)
NewCodes.Name = “Gift”
NewCodes.Parent = CodesFolder
GiveItem(Player,“Gift Model”) – GIVE ITEM
else
print(“allready redeemed”)
end
else
print(“Code expired!”)
end
end)
For some reason in your code it doesn’t look like you’re using your CodeFolders variable, so try utilizing that in the conditional statement right below it because that statement is basically the same thing as your variable, except you’re looking for a specific code within that folder using FindFirstChild.
It would also be really helpful to see the GiveItem function since it looks like that function actually handles the part where you are giving the item to a player.
Well hopefully you changed that conditional statement like I told you to. I would also like to see your GiveItem function.
Whenever the remote event is fired, a new player instance is passed through, so my theory is that before the script gets to that conditional, another player instance has already been passed which is different from the one before it, and since you aren’t using that variable, it’ll create a problem.
function GiveItem(Player,ItemName)
if game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name) then
if game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name).Items:FindFirstChild(ItemName) == nil then
local NewVal = Instance.new(“NumberValue”)
NewVal.Name = ItemName
NewVal.Value = 1
NewVal.Parent = game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name).Items
end
end
end