So, I’ve been trying to make some sort of animation play for all the players found inside a Region3 but it doesn’t seem to work with any of the work I’ve done. Does anyone have an idea on how to fix it?
ServerSide
local region = game.Workspace.MutationRegion3
local region3 = Region3.new(region.Position-(region.Size/2), region.Position+(region.Size/2))
local event = game.ReplicatedStorage.AnimatePlayer
game.Workspace.Trigger.ProximityPrompt.Triggered:Connect(function()
local partsInRegion = workspace:FindPartsInRegion3(region3, region, 1000)
local playersFound = {}
for i, prt in pairs(partsInRegion) do
if prt.Parent:FindFirstChild("Humanoid") then
print("Player ",prt.Parent.Name," Found")
event:FireClient()
end
end
end)
ClientSide
local plr = game.Players.LocalPlayer
local char = plr.Character
game.ReplicatedStorage.AnimatePlayer.OnClientEvent:Connect(function()
local animation = Instance.new("Animation")
local hum = char:FindFirstChild("Humanoid")
animation.Parent = char
animation.AnimationId = "rbxassetid://[INSERTIDHERELOL]"
local loadedTrack = hum:LoadAnimation(animation)
loadedTrack:Play()
end)
-- It's an example, you guys, sorry -------------------------
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
if player.Debounce.Value == false then
game.ReplicatedStorage.RemoteEvents.Power:FireServer(script.Parent.Values)
local action = script.Parent.Parent.Humanoid:LoadAnimation(script.Animation)
action:Play()
end
end)
It’s because you aren’t specifying which player to fire the event to, try this instead for your server side code:
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local event = ReplicatedStorage.AnimatePlayer
local region = workspace.MutationRegion3
local region3 = Region3.new(region.Position-(region.Size/2), region.Position+(region.Size/2))
--//Functions
workspace.Trigger.ProximityPrompt.Triggered:Connect(function()
local partsInRegion = workspace:FindPartsInRegion3(region3, region, 1000)
local playersFound = {}
for i, part in ipairs(partsInRegion) do
local player = Players:GetPlayerFromCharacter(part.Parent)
if player then
print("Player", player.Name, "Found")
event:FireClient(player)
end
end
end)
He’s trying to get every player from the parts found in partsInRegion so it is actually needed, not just the player who triggered the proximity prompt.