So im trying to only fire a remote if the item is a model but it keeps firing the wrong event, the PickupModel event is suppose to fire but instead the PickupItem event is firing, why?
if item:FindFirstChild("Minutes") == nil then
PickupItemPremium:FireServer(item)
else
PickupItem:FireServer(item, item.Minutes.Value) --This is the event being fired
end
if item:IsA("Model") then
PickupModel:FireServer(item, item.Minutes.Value) -- This is the event that should be fired
end
end
That else isn’t on the same indentation, but that might just be formatting.
With normal indenting:
if item:FindFirstChild("Minutes") == nil then
PickupItemPremium:FireServer(item)
else
PickupItem:FireServer(item, item.Minutes.Value) --This is the event being fired
end
if item:IsA("Model") then
PickupModel:FireServer(item, item.Minutes.Value) -- This is the event that should be fired
end
end
As you can see there’s an extra end, which isn’t paired properly. This might just be because of the code snippet, if so please attach more related code.
local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local PickupItemPremium = ReplicatedStorage:WaitForChild("PickupItemPremium")
local PickupModel = ReplicatedStorage:WaitForChild("PickUpModel")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Player = game:GetService("Players").LocalPlayer
local Distance = 20
local Folder = workspace.Items
game:GetService("RunService").RenderStepped:Connect(function()
for i,Obj in pairs(Folder:GetChildren()) do
if Obj:IsA("Tool") then
if Player:DistanceFromCharacter(Obj.Handle.Position) < Distance then
if Obj.Handle:FindFirstChild("Minutes") == nil then
PickupInfoGui.FtoPickup.Text = Obj.Name.." Requires Premium"
PickupInfoGui.Adornee = Obj.Handle
else
PickupInfoGui.Adornee = Obj.Handle
PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle.Minutes.Value.." minutes"
end
end
end
if Obj:IsA("Model") then
if Player:DistanceFromCharacter(Obj.HumanoidRootPart.Position) < Distance then
PickupInfoGui.Adornee = Obj.HumanoidRootPart or Obj.Hitbox
PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.HumanoidRootPart.Minutes.Value.." minutes"
end
end
end
end)
Is this related to the original code? I was looking for the code surrounding your original snippet, as that’s what fires the remote event, and likely contains the issue.
local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local PickupItemPremium = ReplicatedStorage:WaitForChild("PickupItemPremium")
local PickupModel = ReplicatedStorage:WaitForChild("PickUpModel")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Player = game:GetService("Players").LocalPlayer
local Distance = 20
local Folder = workspace.Items
game:GetService("RunService").RenderStepped:Connect(function()
for i,Obj in pairs(Folder:GetChildren()) do
if Obj:IsA("Tool") then
if Player:DistanceFromCharacter(Obj.Handle.Position) < Distance then
if Obj.Handle:FindFirstChild("Minutes") == nil then
PickupInfoGui.FtoPickup.Text = Obj.Name.." Requires Premium"
PickupInfoGui.Adornee = Obj.Handle
else
PickupInfoGui.Adornee = Obj.Handle
PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.Handle.Minutes.Value.." minutes"
end
end
end
if Obj:IsA("Model") then
if Player:DistanceFromCharacter(Obj.HumanoidRootPart.Position) < Distance then
PickupInfoGui.Adornee = Obj.HumanoidRootPart or Obj.Hitbox
PickupInfoGui.FtoPickup.Text = Obj.Name.." - "..Obj.HumanoidRootPart.Minutes.Value.." minutes"
end
end
end
end)
local debounce = false
UIS.InputBegan:Connect(function(input, processed)
if not debounce then
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
debounce = true
local item = mouse.Target
if item then
local distanceFromItem = player:DistanceFromCharacter(item.Position)
if distanceFromItem < 30 then
if item:FindFirstChild("Minutes") == nil then
PickupItemPremium:FireServer(item)
else
PickupItem:FireServer(item, item.Minutes.Value)
end
if item:IsA("Model") then
PickupModel:FireServer(item, item.Minutes.Value)
end
end
end
end
end
wait(5)
debounce = false
end
end)
Server
local MarketplaceService = game:GetService("MarketplaceService")
game.ReplicatedStorage:WaitForChild("PickupItem").OnServerEvent:Connect(function(player, item, itemMins)
local itemname = item.Parent.Name
local newItem = item.Parent:Clone()
if player:WaitForChild("leaderstats").Minutes.Value >= itemMins and not player.Backpack:FindFirstChild(itemname) and not player.Character:FindFirstChild(itemname) then
newItem.Parent = player.Backpack
newItem.Handle.Anchored = false
end
end)
game.ReplicatedStorage:WaitForChild("PickupItemPremium").OnServerEvent:Connect(function(player, item)
local itemname = item.Parent.Name
local newItem = item.Parent:Clone()
if itemname == "WoodSword" then
if player.MembershipType == Enum.MembershipType.Premium then
newItem.Parent = player.Backpack
newItem.Handle.Anchored = false
elseif player.MembershipType == Enum.MembershipType.None then
MarketplaceService:PromptPremiumPurchase(player)
end
end
end)
game.ReplicatedStorage:WaitForChild("PickUpModel").OnServerEvent:Connect(function(player, item, itemMins)
local itemname = item.Name
if player:WaitForChild("leaderstats").Minutes.Value >= itemMins and not player.Character:FindFirstChild(itemname) then
local CharacterClone = game.ReplicatedStorage:FindFirstChild("Imposter"):Clone()
CharacterClone.Name = player.Name
player.Character:Destroy()
player.Character = CharacterClone
CharacterClone.Parent = game.Workspace
end
end)
Ah, that’s much better. Your issue is you still will end up firing one of the other two events even if item is a model.
Change this:
if item:FindFirstChild("Minutes") == nil then
PickupItemPremium:FireServer(item)
else
PickupItem:FireServer(item, item.Minutes.Value)
end
if item:IsA("Model") then
PickupModel:FireServer(item, item.Minutes.Value)
end
To this:
if item:IsA("Model") then
PickupModel:FireServer(item, item.Minutes.Value)
else
if item:FindFirstChild("Minutes") == nil then
PickupItemPremium:FireServer(item)
else
PickupItem:FireServer(item, item.Minutes.Value)
end
end
That way, you use the proper event regardless.
If it still doesn’t work: add print statements and verify that item is a Model.
yes, it doesn’t. I fired a different event and it’s running this event
game.ReplicatedStorage:WaitForChild("PickupItem").OnServerEvent:Connect(function(player, item, itemMins)
local itemname = item.Parent.Name
local newItem = item.Parent:Clone()
if player:WaitForChild("leaderstats").Minutes.Value >= itemMins and not player.Backpack:FindFirstChild(itemname) and not player.Character:FindFirstChild(itemname) then
newItem.Parent = player.Backpack
newItem.Handle.Anchored = false
end
end)