So basically, I have a cleaning script (I followed a YT tutorial). The script will only be for a certain group rank and that script will be included later. So, to do this I can't have players pick up the Tool from the ground in Workspace, but work when it's given to them from Server Storage into their Backpack. When I do this, however, it fails to work.
If it helps, I followed RoScripter YouTube video.
Mop Script:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local MopAnimation = script.Parent.MopAnimation
local Equipped = false
local Mopping = false
local function isTargetASpill(Spill)
if Spill.Parent == game.Workspace.SpillLocations then
return true
end
end
script.Parent.Equipped:Connect(function()
Equipped = true
end)
script.Parent.Unequipped:Connect(function()
Equipped = false
end)
UserInputService.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.Keyboard then
if Input.KeyCode == Enum.KeyCode.E and Equipped == true and Mouse.Target and isTargetASpill(Mouse.Target) and Mopping == false then
print("Pressed E while the tool was equipped")
local Target = Mouse.Target
Target.MopSpill:FireServer()
local MopAnimationTrack = Player.Character.Humanoid:LoadAnimation(MopAnimation)
MopAnimationTrack.Looped = true
MopAnimationTrack:Play()
Mopping = true
wait(5)
MopAnimationTrack:Stop()
Mopping = false
print(Target.Name)
end
end
end)
Spill Manager
local TweenService = game:GetService("TweenService")
local SpillLocationsFolder = game.Workspace.SpillLocations
local SpillLocations = SpillLocationsFolder:GetChildren()
for i = 1, #SpillLocations do
local Spill = SpillLocations[i]
local MopSpillEvent = Spill.MopSpill
MopSpillEvent.OnServerEvent:Connect(function(Player)
print("Cleaning Spill")
local Tween = TweenService:Create(Spill, TweenInfo.new(5), {Size = Vector3.new(0, 0, 0)})
Tween:Play()
wait(5)
Spill.Transparency = 1
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 1
end)
end
while true do
local RandomSpill = SpillLocations[math.random(1, #SpillLocations)]
RandomSpill.Transparency = 0
RandomSpill.BrickColor = BrickColor.Random()
RandomSpill.Size = Vector3.new(0.1, 4.4, 4.65)
wait(60)
end
