-
What do you want to achieve? Keep it simple and clear!
I wanted to make a restock systems that when players interacted and It will highlight shelf that currently not stocked. -
What is the issue? Include screenshots / videos if possible!
It not adding a highlight to the shelf. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tries Searching in Devforum and Googles but couldn’t find possible way.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Assets = ServerStorage.Assets
local anim = Assets.Animations.Pickup
local Set = ReplicatedStorage.Request.Set
local Create = ReplicatedStorage.Request.Create
local Restock = Workspace.Worlds.Objectives.Restock
local Asset = Restock.Assets:GetDescendants()
local Shelf = Restock.Shelf:GetDescendants()
local playerTracks = {}
local function Highlight(player, Shelf)
if Shelf and Shelf.Stocked and Shelf.Stocked.Value ~= nil then
if Shelf.Stocked.Value == false then
Create:FireClient(player, Shelf)
elseif Shelf.Stocked.Value == true then
print("a")
end
end
end
local function Interaction(player, box)
local Character = player.Character
if not Character then
return
end
local humanoid = Character:WaitForChild("Humanoid")
if (not Workspace.Worlds.Temp:FindFirstChild(player.Name .. "_Boxes")) and (not Character:FindFirstChildOfClass("Tool")) and (not Workspace.Worlds.Temp:FindFirstChild(player.Name .. "_Garbage")) then
humanoid.WalkSpeed = 9
Character.IsCarrying.Value = true
local model = Assets.Boxes:FindFirstChild("Box"):Clone()
model.Parent = Workspace.Worlds.Temp
model.CanCollide = false
model.Name = player.Name .. "_Boxes"
local weldConstraint = model:FindFirstChildWhichIsA("WeldConstraint")
if not weldConstraint then
weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Parent = model
model.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, -0.3, -2)
weldConstraint.Part0 = model
weldConstraint.Part1 = Character.UpperTorso
else
weldConstraint:Destroy()
end
local track = humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Movement
track.Looped = true
track:Play()
Set:FireClient(player,box.ProximityPrompt,false)
model.Equipped:Play()
playerTracks[player] = track
end
end
local function Drop(player, box)
local Character = player.Character
if not Character then
return
end
local humanoid = Character:WaitForChild("Humanoid")
local existing = Workspace.Worlds.Temp:FindFirstChild(player.Name .. "_Boxes")
if existing then
existing.Unequipped:Play()
task.wait(.3)
box.Parent.Shelf.Stocked.Value = true
existing:Destroy()
Character.IsCarrying.Value = false
humanoid.WalkSpeed = 16
Set:FireClient(player,box.ProximityPrompt,false)
for i,v in pairs(box.Parent.Shelf.Boxes:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
local track = playerTracks[player]
if track then
track:Stop()
playerTracks[player] = nil
end
end
end
for _, prompt in pairs(Asset) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
Interaction(player, prompt.Parent)
for _, prompt1 in pairs(Shelf) do
if prompt1:IsA("ProximityPrompt") then
Set:FireClient(player,prompt1,true)
Highlight(prompt1.Parent)
end
end
end)
end
end
for _, prompt in pairs(Shelf) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function(player)
local pShelf = prompt.Parent.Parent.Shelf
local cTrashBin = pShelf:FindFirstChild("Trash Bin")
if cTrashBin then
if cTrashBin:IsA("Model") and cTrashBin.Parent:FindFirstChild("Stocked") then
if cTrashBin.Parent.Stocked.Value == true then
cTrashBin.Parent.Stocked.Value = false
Set:FireClient(player, prompt.Parent, false)
end
end
end
Drop(player, prompt.Parent)
for _, prompt1 in pairs(Asset) do
if prompt1:IsA("ProximityPrompt") then
Set:FireClient(player, prompt1, true)
end
end
end)
end
end
and this is client:
local player = game.Players.LocalPlayer
local character = player.Character
local IsCarrying = character:WaitForChild("IsCarrying")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Create = ReplicatedStorage.Request.Create
local Set = ReplicatedStorage.Request.Set
if IsCarrying and IsCarrying:IsA("BoolValue") then
local function check()
if IsCarrying.Value == true then
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
else
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end
end
IsCarrying:GetPropertyChangedSignal("Value"):Connect(function()
check()
end)
end
Set.OnClientEvent:Connect(function(Prompt,Value)
Prompt.Enabled = Value
end)
Create.OnClientEvent:Connect(function(Shelf)
local a = script.Highlight:Clone()
a.Parent = Shelf
end)