-
What do you want to achieve?
So basically it’s an animal survival game where carnivores are able to pick up meat and ofc herbivores not. That works fine! I want the player to just be able to pick up one block (meat) at a time, and to pick up another one the player has to drop the current block. -
What is the issue?
My only problem is that, if the player has picked up the block (meat), it’s able to pick up another block at the same time and so on. So the player is able to run around with 3 blocks while it looks like one. -
What solutions have you tried so far?
Asked in server for help, looked at the devhub.
Here is my code I think is nessescary to solve this issue.
ServerGrabBlock (Serverscript)
local weld = Instance.new("Weld")
local char = plr.Character
local jaw = char.Jaw:WaitForChild("Jaw")
-----
local humanoid = char:WaitForChild("Humanoid")
local Carnivore = humanoid:GetAttribute("Carnivore")
local Herbivore = humanoid:GetAttribute("Herbivore")
local Omnivore = humanoid:GetAttribute("Omnivore")
if Carnivore == true or Omnivore == true then
weld.Parent = block
weld.Part0 = block
weld.Part1 = jaw
block.CFrame = jaw.CFrame
block.Position = block.Position + jaw.CFrame.LookVector
weld.Name = "BlockWeld"
block.Grab.MaxActivationDistance = 0
wait(1)
CanThrowBlock = true
end
---------
end
local function ThrowBlock(plr, block)
if CanThrowBlock == true then
local weld = block:WaitForChild("BlockWeld")
if weld:IsA("Weld") then
weld:Destroy()
block.Grab.MaxActivationDistance = 32
end
CanThrowBlock = false
end
end
GrabBlockLocal (LocalScript)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharachterAdded:Wait()
local uis = game:GetService("UserInputService")
local hum = char:WaitForChild("Humanoid")
local CanGrabBlock = true
local function Block(plr, block)
if CanGrabBlock == true then
CanGrabBlock = false
game.ReplicatedStorage.TakeBlock:FireServer(plr, block)
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.C then
game.ReplicatedStorage.ThrowBlock:FireServer(plr, block)
wait(1)
CanGrabBlock = true
end
end)
end
end
game.ReplicatedStorage.ClientBlock.OnClientEvent:Connect(Block)