Server view in testing cannot see player holding tool

  1. What do you want to achieve? Keep it simple and clear!
    Giving a player a tool that everyone can see when they hold it.
  2. What is the issue? Include screenshots / videos if possible!
    In testing, when I go to server side, the tool is not there.

This script gives the player the tool.
Ignore all the other food items, just the raw chicken for now, the lines of script that give the tool are at the very bottom.

--|OTHER|--
local UI = script.Parent.MainFrame
local DB = false
local sound1 = script.Parent["Open/Close"]
local sound2 = script.Parent.Click
local sound3 = script.Parent.Hover

--|FOOD|--
local FoodFrame = UI.FoodFrame
local FoodList = FoodFrame.Food
--FOOD ITEMS--
local RawChicken = FoodList.RawChicken
local RawSteak = FoodList.RawSteak
local Ham = FoodList.Ham
local IceCream = FoodList.IceCream
local Eggs = FoodList.Eggs
local Beef = FoodList.Beef
local Carrots = FoodList.Carrots
local Cheese = FoodList.Cheese
local Tomato = FoodList.Tomato
local Celery = FoodList.Celery
local Lettuce = FoodList.Lettuce
local Fish = FoodList.Fish

--|FOOD BUTTONS|--
local RCB = RawChicken.TextButton
local RSB = RawSteak.TextButton
local HB = Ham.TextButton
local ICB = IceCream.TextButton
local EB = Eggs.TextButton
local BB = Beef.TextButton
local CB = Carrots.TextButton
local CHB = Cheese.TextButton
local TB = Tomato.TextButton
local CEB = Celery.TextButton
local LB = Lettuce.TextButton
local FB = Fish.TextButton

--|BUTTON ANIMATIONS|--
local DarkColor = Color3.fromRGB(73, 73, 74)
local LightColor = Color3.fromRGB(162, 162, 162)

RawChicken.MouseEnter:Connect(function()
	sound3:Play()
	RawChicken.BackgroundColor3 = DarkColor
end)

RawChicken.MouseLeave:Connect(function()
	sound3:Play()
	RawChicken.BackgroundColor3 = LightColor
end)
RawSteak.MouseEnter:Connect(function()
	sound3:Play()
	RawSteak.BackgroundColor3 = DarkColor
end)

RawSteak.MouseLeave:Connect(function()
	sound3:Play()
	RawSteak.BackgroundColor3 = LightColor
end)

Ham.MouseEnter:Connect(function()
	sound3:Play()
	Ham.BackgroundColor3 = DarkColor
end)

Ham.MouseLeave:Connect(function()
	sound3:Play()
	Ham.BackgroundColor3 = LightColor
end)

IceCream.MouseEnter:Connect(function()
	sound3:Play()
	IceCream.BackgroundColor3 = DarkColor
end)

IceCream.MouseLeave:Connect(function()
	sound3:Play()
	IceCream.BackgroundColor3 = LightColor
end)

Eggs.MouseEnter:Connect(function()
	sound3:Play()
	Eggs.BackgroundColor3 = DarkColor
end)

Eggs.MouseLeave:Connect(function()
	sound3:Play()
	Eggs.BackgroundColor3 = LightColor
end)

Beef.MouseEnter:Connect(function()
	sound3:Play()
	Beef.BackgroundColor3 = DarkColor
end)

Beef.MouseLeave:Connect(function()
	sound3:Play()
	Beef.BackgroundColor3 = LightColor
end)

Carrots.MouseEnter:Connect(function()
	sound3:Play()
	Carrots.BackgroundColor3 = DarkColor
end)

Carrots.MouseLeave:Connect(function()
	sound3:Play()
	Carrots.BackgroundColor3 = LightColor
end)

Cheese.MouseEnter:Connect(function()
	sound3:Play()
	Cheese.BackgroundColor3 = DarkColor
end)

Cheese.MouseLeave:Connect(function()
	sound3:Play()
	Cheese.BackgroundColor3 = LightColor
end)

Tomato.MouseEnter:Connect(function()
	sound3:Play()
	Tomato.BackgroundColor3 = DarkColor
end)

Tomato.MouseLeave:Connect(function()
	sound3:Play()
	Tomato.BackgroundColor3 = LightColor
end)

Celery.MouseEnter:Connect(function()
	sound3:Play()
	Celery.BackgroundColor3 = DarkColor
end)

Celery.MouseLeave:Connect(function()
	sound3:Play()
	Celery.BackgroundColor3 = LightColor
end)

Lettuce.MouseEnter:Connect(function()
	sound3:Play()
	Lettuce.BackgroundColor3 = DarkColor
end)

Lettuce.MouseLeave:Connect(function()
	sound3:Play()
	Lettuce.BackgroundColor3 = LightColor
end)

Fish.MouseEnter:Connect(function()
	sound3:Play()
	Fish.BackgroundColor3 = DarkColor
end)

Fish.MouseLeave:Connect(function()
	sound3:Play()
	Fish.BackgroundColor3 = LightColor
end)


--|BUTTON OUTPUTS|--
local player = game.Players.LocalPlayer

RCB.MouseButton1Click:Connect(function()
	if not DB then
		DB = true
		sound2:Play()
		local ChickenModel = game.ReplicatedStorage.RawChicken:Clone()
		ChickenModel.Parent = player.Backpack
		local ChickenHandle = game.ReplicatedStorage.RawChicken.Handle
		local Weld = Instance.new("Weld")
		Weld.Part0 = player.Character.RightHand
		Weld.Part1 = ChickenHandle
		Weld.C0 = CFrame.new(0, 0, 0)
		Weld.Parent = ChickenHandle
		wait(10)
		DB = false
	end
end)
2 Likes

According to this, I’m going to assume that this is a LocalScript. Please correct me if I’m wrong.

The server cannot see the player holding the tool, and other players also won’t be able to see it because you are cloning the tool on the client.

To fix this issue, I recommend setting up a RemoteEvent.

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- For the sake of simplicity, I put this directly under ReplicatedStorage.
-- However, I recommend using folders to organize.
local GiveToolEvent = ReplicatedStorage.GiveToolEvent

GiveToolEvent.OnServerEvent:Connect(function(player)
	-- Give the player the chicken on the server, so everyone can see it.
	local ChickenModel = ReplicatedStorage.RawChicken:Clone()
	ChickenModel.Parent = player.Backpack
	local ChickenHandle = ReplicatedStorage.RawChicken.Handle
	local Weld = Instance.new("Weld")
	Weld.Part0 = player.Character.RightHand
	Weld.Part1 = ChickenHandle
	Weld.C0 = CFrame.new(0, 0, 0)
	Weld.Parent = ChickenHandle
end)

Modified local script:

--|BUTTON OUTPUTS|--
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- For the sake of simplicity, I put this directly under ReplicatedStorage.
-- However, I recommend using folders to organize.
local GiveToolEvent = ReplicatedStorage.GiveToolEvent

local player = game.Players.LocalPlayer

RCB.MouseButton1Click:Connect(function()
	if not DB then
		DB = true
		sound2:Play()
		GiveToolEvent:FireServer() -- Tell the server to give the player chicken.
		wait(10)
		DB = false
	end
end)

Hope this helps!

2 Likes

Screenshot 2023-07-31 at 10.01.16 AM
Does not work, anything wrong with this script, The local script called food is the one we were talking about and theChicken script is the other one I made.

2 Likes

You should use :EquipTool()

Modified server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- For the sake of simplicity, I put this directly under ReplicatedStorage.
-- However, I recommend using folders to organize.
local GiveToolEvent = ReplicatedStorage.GiveToolEvent

GiveToolEvent.OnServerEvent:Connect(function(player)
	local ChickenTool = ReplicatedStorage.RawChicken:Clone()
	local character = player.Character or player.CharacterAdded:Wait() -- gets the player's character
	local humanoid = character:FindFirstChildOfClass("Humanoid") -- get the humanoid
	ChickenTool.Parent = player.Backpack -- put in backpack
	humanoid:EquipTool(ChickenTool) --equip the tool
end)
2 Likes

Why is your script at replicated storage, I recommend putting most of your server scripts in serverscriptservice

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.