Hi. I’m trying to make a mopping/janitor system for my game. I want it to freeze the player’s jumppower and walkspeed when they touch a spill and have the mop equipped as well as play a mopping animation and increase their leaderstats.
My problem is that the animation is playing only for the player who mops the spill on a client-side, and I want it to play server-sided. Despite trying lots of solutions to fix this, it still won’t work. Any help with this would be appreciated.
Local Script under StarterPlayerScripts (to play animation):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local remote = ReplicatedStorage.AnimationForSpill
local animation = ReplicatedStorage.MopAnimation
remote.OnClientEvent:Connect(function()
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if not humanoid then
return
end
humanoid.Animator:LoadAnimation(animation):Play()
end)
Script Under Mop:
local TweenService = game:GetService("TweenService")
local spill = game:GetService("ServerStorage").Spill
local TWEEN_INFO = TweenInfo.new(
4,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
)
local mop = script.Parent
local player = mop.Parent.Parent
local character = player.Character or player.CharacterAdded:Wait()
local activated = false
mop.Touch.Touched:Connect(function(hit)
if hit.Parent ~= workspace.Spills or hit.Size ~= spill.Size or activated then
return
end
activated = true
local humanoid = character.Humanoid
humanoid.JumpPower = 0
humanoid.WalkSpeed = 0
game.ReplicatedStorage.AnimationForSpill:FireClient(player)
local tween = TweenService:Create(hit, TWEEN_INFO, {
Size = Vector3.new()
})
tween:Play()
tween.Completed:Wait()
humanoid.JumpPower = 50
humanoid.WalkSpeed = 16
hit:Destroy()
player.leaderstats.Points.Value += 2
activated = false
end)
‘SpillHandler’ Script:
local ServerStorage = game:GetService("ServerStorage")
local TIME_RANGE = NumberRange.new(5, 30)
local LIMIT = 100
local spillAreas = workspace.SpillAreas:GetChildren()
local spillsFolder = workspace.Spills
local spill = ServerStorage.Spill
local spillColors = {
Color3.fromRGB(180, 255, 189),
Color3.fromRGB(255, 245, 129),
Color3.fromRGB(255, 96, 120),
Color3.fromRGB(199, 234, 255)
}
local random = Random.new()
local function getRandomColor()
return random:NextInteger(0, 255)
end
while true do
if #spillsFolder:GetChildren() < LIMIT then
wait(random:NextInteger(TIME_RANGE.Min, TIME_RANGE.Max))
local randomArea = spillAreas[random:NextInteger(1, #spillAreas)]
local areaSize = randomArea.Size * 0.5
local bottomLeft = randomArea.Position - areaSize
local TopRight = randomArea.Position + areaSize
local newSpill = spill:Clone()
newSpill.Color = Color3.new(getRandomColor(), getRandomColor(), getRandomColor())
newSpill.Parent = workspace.Spills
repeat
newSpill.CFrame = CFrame.new(
random:NextInteger(bottomLeft.X, TopRight.X),
bottomLeft.Y,
random:NextInteger(bottomLeft.Z, TopRight.Z)
) * CFrame.Angles(0, math.rad(random:NextInteger(-179, 179)), math.rad(90))
until #newSpill:GetTouchingParts() <= 1
else
spillsFolder.ChildRemoved:Wait()
end
end