Hello! I have an issue, I have a script in a ScreenGui and it’s in StarterGui the issue is server only fires for the first player to join for example:
the second player when holding 1 isn’t anchored, a second shield isn’t created etc. Any help is appreciated!
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local shieldAnimation = Instance.new("Animation")
shieldAnimation.AnimationId = "rbxassetid://idhere"
local loadShield = char:WaitForChild("Humanoid"):LoadAnimation(shieldAnimation)
script:WaitForChild("PlayerChangedEvent"):FireServer()
local shieldDb = script:WaitForChild("shieldDb")
local shieldFrame = script.Parent:WaitForChild("shieldFrame")
UIS.InputBegan:Connect(function(input, GPE)
if GPE then return end
print(table.foreach(UIS:GetKeysPressed(), print))
if input.KeyCode == Enum.KeyCode.One then
print(shieldDb.Value)
while true do wait()
if UIS:IsKeyDown(Enum.KeyCode.One) and not shieldDb.Value then
print('e')
script:WaitForChild("ShieldEvent"):FireServer(true)
if not loadShield.IsPlaying then
loadShield:Play()
end
else
print('h')
script:WaitForChild("ShieldEvent"):FireServer(false)
if loadShield.IsPlaying then
loadShield:Stop()
end
shieldFrame:WaitForChild("shieldLabel").Size = UDim2.new(1,0,1,0)
shieldDb.Value = true
break
end
end
end
end)
shieldDb.Changed:Connect(function()
if shieldDb.Value == true then
for i = 0, 1, 0.1 do
wait(0.5)
local sizeToDo = shieldFrame:WaitForChild("shieldLabel").Size:Lerp(UDim2.new(1,0,0,0), i)
shieldFrame.shieldLabel:TweenSize(sizeToDo, Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, false)
print(sizeToDo)
print(i)
end
shieldDb.Value = false
end
end)
-- this is the local script,
local shield = script.Parent:WaitForChild("ShieldEvent")
local changedevent = script.Parent:WaitForChild("PlayerChangedEvent")
local Physic = game:GetService("PhysicsService")
local names = {"Shield", "Caster"}
local playersGroup = Physic:CreateCollisionGroup(names[1])
local castersGroup = Physic:CreateCollisionGroup(names[2])
local disconnectShieldLoop
local shieldMesh = Instance.new("Part")
shieldMesh.Parent = game:GetService('ReplicatedStorage')
shieldMesh.Anchored = false
shieldMesh.CanCollide = true
shieldMesh.Material = Enum.Material.ForceField
shieldMesh.BrickColor = BrickColor.new("Really black")
shieldMesh.Size = Vector3.new(12,12,12)
shieldMesh.Name = "HATEShield"
shieldMesh.Shape = "Ball"
local w = Instance.new("WeldConstraint")
w.Parent = shieldMesh
local shieldDb = false
local function onPlayerChanged(caster)
for i,v in pairs(game:GetService('Players'):GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
for y,x in pairs(char:GetChildren()) do
if v.UserId == caster.UserId then
if x:IsA("BasePart") then
Physic:SetPartCollisionGroup(x, names[2])
end
end
end
end
Physic:SetPartCollisionGroup(shieldMesh, names[1])
Physic:CollisionGroupSetCollidable(names[1], names[2], false)
end
shield.OnServerEvent:Connect(function(plr, isPressed)
local char = plr.Character or plr.CharacterAdded:Wait()
if not shieldDb then
shieldDb = true
onPlayerChanged(plr)
end
if isPressed then
char:WaitForChild("HumanoidRootPart").Anchored = true
shieldMesh.CFrame = char.HumanoidRootPart.CFrame
shieldMesh.Parent = workspace
w.Part0 = char:WaitForChild("HumanoidRootPart")
w.Part1 = shieldMesh
else
char:WaitForChild("HumanoidRootPart").Anchored = false
shieldMesh.Parent = game:GetService('ReplicatedStorage')
end
end) -- this is the normal script