I’ve been trying to make a little script that plays a tween whenever player is given or has forcefield however it does not seem to fire. any ideas? Perhaps its the characteradded function?
This is a localscript.
player.CharacterAdded:Connect(function(__CHAR)
if __CHAR:FindFirstChildOfClass("ForceField") then
game:GetService("TweenService"):Create(__SHIELDICON, TweenInfo.new(1), {ImageTransparency = 0.2}):Play()
end
__CHAR.ChildAdded:Connect(function(__INST)
if __INST:IsA("ForceField") then
game:GetService("TweenService"):Create(__SHIELDICON, TweenInfo.new(1), {ImageTransparency = 0.2}):Play()
end
end)
__CHAR.ChildRemoved:Connect(function(__INST)
if __INST:IsA("ForceField") then
game:GetService("TweenService"):Create(__SHIELDICON, TweenInfo.new(1), {ImageTransparency = 1}):Play()
end
end)
end)
Please keep in mind that a server-script is used to give the player forcefield
Try adding a wait() on the first line within the event connection function (above the if). It may be that the events are being run out of order. If you use the player.CharacterAdded event on the server to put the force field on the character, the client may run the CharacterAdded event before processing the force field.
Nope still dosen’t work
Also this is how the server event works.
__GIVEFF.OnServerEvent:Connect(function(__PLAY,__WHICH)
if __WHICH == "On" then
local __FF = Instance.new("ForceField")
__FF.Name = "__SHOPFF"
__FF.Parent = __PLAY.Character
elseif __WHICH == "Off" then
if __PLAY.Character:FindFirstChildOfClass("ForceField") then
__PLAY.Character:FindFirstChildOfClass("ForceField"):Destroy()
else
return
end
end
end)
Tried debugging and turns out the characteradded function was the problem, why is that?
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait(function(__CHAR)
if __CHAR:FindFirstChildOfClass("ForceField") then
print("CHARACTER SPAWNED WITH FF")
game:GetService("TweenService"):Create(__SHIELDICON, TweenInfo.new(1), {ImageTransparency = 0.2}):Play()
print("CHARACTER SPAWNED WITH FF REMOVED")
end
__CHAR.ChildAdded:Connect(function(__INST)
if __INST:IsA("ForceField") then
print("CHARACTER GIVEN FF")
game:GetService("TweenService"):Create(__SHIELDICON, TweenInfo.new(1), {ImageTransparency = 0.2}):Play()
print("CHARACTER GIVEN FF REMOVED")
end
end)
__CHAR.ChildRemoved:Connect(function(__INST)
if __INST:IsA("ForceField") then
print("CHARACTER REMOVED FF")
game:GetService("TweenService"):Create(__SHIELDICON, TweenInfo.new(1), {ImageTransparency = 1}):Play()
end
end)
end)
Are you sure that your CharacterAdded event is being connected at all? Also make sure that it is connected before any character is added. For example, if you put this :
inside a localscript within the character itself, it won’t fire.
No you don’t need a fire client event. If your localscript is in the character itself, just move it to the StarterPlayerScripts instead of the StarterCharacterScripts.