Tried to send a value from the server to the client, and I passed the Player object but nothing happened… The local script (script on the receiving end of the remote) was supposed to tween a part, but it didn’t, here is both the server and client script.
Server:
local Shield = game.ReplicatedStorage.Meshes.Shield:Clone()
local Event = game.ReplicatedStorage.CombatEvents.Shield
Event.OnServerEvent:Connect(function(Player, BlockingStatus)
local Plr = Player
local c = Player.Character
if BlockingStatus == "IsBlocking" then
local Shield = game.ReplicatedStorage.Meshes.Shield:Clone()
Event:FireClient(Plr, "IsBlocking")
Shield.Parent = c.HumanoidRootPart
Shield.Position = c.HumanoidRootPart.Position
Shield.Anchored = false
local Weld = Instance.new("Weld", Shield)
Weld.Part0 = c.HumanoidRootPart
Weld.Part1 = Shield
elseif BlockingStatus == "StoppedBlocking" then
Event:FireClient(Plr, "StoppedBlocking")
else
return
end
end)
Local Script:
game.ReplicatedStorage.CombatEvents.Shield.OnClientEvent:Connect(function(Player, Action)
if Action == "IsBlocking" then
print("player blocking")
if Player.Character.HumanoidRootPart:FindFirstChild("Shield") then
print("player has shield")
local Shield = Player.Character.HumanoidRootPart:FindFirstChild("Shield")
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local Goals = {}
Goals.Size = Vector3.new(7,7,7)
local Tween = TweenService:Create(Shield, Info, Goals)
Tween:Play()
end
elseif Action == "StoppedBlocking" then
if Player.Character.HumanoidRootPart:FindFirstChild("Shield") then
local Shield = Player.Character.HumanoidRootPart:FindFirstChild("Shield")
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local Goals = {}
Goals.Size = Vector3.new(0.5,0.5,0.5)
local Tween = TweenService:Create(Shield, Info, Goals)
Tween:Play()
end
end
end)
Please help!
Only briefly looked at this for 10 seconds, OnClientEvent only has tuple arguments to pass through
Even if you reference it as a parameter, you can instead easily get the Player by just using game.Players.LocalPlayer, the only other time when you’d need to reference the player inside the parameter is if you call OnServerEvent
game.ReplicatedStorage.CombatEvents.Shield.OnClientEvent:Connect(function(Action)
Well I need to get the player from the server and send it to the client, I believe…
I tried to omit the Player argument when I sent a message to the Client, and that just raised an error: “Unable to cast value to object”
Are you sure you’re referencing a valid Player object? Also I’m unsure as to why you referenced a Plr variable inside your OnServerEvent, when you could just simply get the Player argument instead to fire the client on
It should look something like this:
--Server
local Shield = game.ReplicatedStorage.Meshes.Shield:Clone()
local Event = game.ReplicatedStorage.CombatEvents.Shield
Event.OnServerEvent:Connect(function(Player, BlockingStatus)
local c = Player.Character
if BlockingStatus == "IsBlocking" then
local Shield = game.ReplicatedStorage.Meshes.Shield:Clone()
Event:FireClient(Player, "IsBlocking")
Shield.Parent = c.HumanoidRootPart
Shield.Position = c.HumanoidRootPart.Position
Shield.Anchored = false
local Weld = Instance.new("Weld", Shield)
Weld.Part0 = c.HumanoidRootPart
Weld.Part1 = Shield
elseif BlockingStatus == "StoppedBlocking" then
Event:FireClient(Player, "StoppedBlocking")
else
return
end
end)
--Client
game.ReplicatedStorage.CombatEvents.Shield.OnClientEvent:Connect(function(Action)
if Action == "IsBlocking" then
print("player blocking")
if Player.Character.HumanoidRootPart:FindFirstChild("Shield") then
print("player has shield")
local Shield = Player.Character.HumanoidRootPart:FindFirstChild("Shield")
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local Goals = {}
Goals.Size = Vector3.new(7,7,7)
local Tween = TweenService:Create(Shield, Info, Goals)
Tween:Play()
end
elseif Action == "StoppedBlocking" then
if Player.Character.HumanoidRootPart:FindFirstChild("Shield") then
local Shield = Player.Character.HumanoidRootPart:FindFirstChild("Shield")
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local Goals = {}
Goals.Size = Vector3.new(0.5,0.5,0.5)
local Tween = TweenService:Create(Shield, Info, Goals)
Tween:Play()
end
end
end)
Yeah, it worked thanks! (Sorry for late reply, had to do something)