Hi kuu, it looks like Roblox Studio doesn’t recognize what you’re trying to reference, which is why it is saying player is “nil.”
Make sure to load the local player into your script before referencing it. Like msix29 pointed out, the LocalPlayer variable can also only be used in LocalScripts.
local player = game:GetService("Players").LocalPlayer
repeat wait() until script.Parent
local targetfound = false
repeat wait() until script.Parent.Name ~= "ErrorSansAttacks"
local mag = 4000
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
--================TargetPosition========================
local players = game.Players:GetChildren()
local range = 300
local lastmag= 1000
local mTorso = script.Parent.Parent:FindFirstChild("Torso")
local mHum = script.Parent:FindFirstChild("Humanoid")
local targetplayer = nil--players[1]
for i=1,#players do
wait()
if players[i].Character then
local char = players[i].Character
if char:FindFirstChild("Torso") then
local Torso = char:FindFirstChild("Torso")
local mag = (Torso.Position - script.Parent.Torso.Position).magnitude
if mag<=range then
if char.Name ~= script.Parent.Parent then
if mag < lastmag then
mag = (Torso.Position - script.Parent.Torso.Position).magnitude
lastmag = mag
targetplayer = players[i]
end
end
end
end
end
end -- end of for loop
local stringscreen = math.random(1,3)
if stringscreen == 1 then
local one = script.String1:Clone()
one.Parent = player.PlayerGui
wait(7.5)
one:Destroy()
script:Destroy()
end
if stringscreen == 2 then
local two = script.String2:Clone()
two.Parent = player.PlayerGui
wait(7.5)
two:Destroy()
script:Destroy()
end
if stringscreen == 3 then
local three = script.String3:Clone()
three.Parent = player.PlayerGui
wait(7.5)
three:Destroy()
script:Destroy()
end
--==========================
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
I still dont know why it is not working but it shouldnt
Let’s say that our remoteEvent (In replicated storage) is called “RemoteEvent”
In the serverscript, in place of the code in the main post, you could have:
if stringscreen == 1 then
game.ReplicatedStorage:FireClient()
end
And in a localsript:
player = game.Players.LocalPlayer
game.ReplicatedStorage.OnClientEvent:Connect(function()
local one = script.String1:Clone()
one.Parent = player.PlayerGui
wait(7.5)
one:Destroy()
script:Destroy()
end)
repeat wait() until script.Parent
local targetfound = false
repeat wait() until script.Parent.Name ~= "ErrorSansAttacks"
local mag = 4000
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
--================TargetPosition========================
local players = game.Players:GetChildren()
local range = 300
local lastmag= 1000
local mTorso = script.Parent.Parent:FindFirstChild("Torso")
local mHum = script.Parent:FindFirstChild("Humanoid")
local targetplayer = nil--players[1]
for i=1,#players do
wait()
if players[i].Character then
local char = players[i].Character
if char:FindFirstChild("Torso") then
local Torso = char:FindFirstChild("Torso")
local mag = (Torso.Position - script.Parent.Torso.Position).magnitude
if mag<=range then
if char.Name ~= script.Parent.Parent then
if mag < lastmag then
mag = (Torso.Position - script.Parent.Torso.Position).magnitude
lastmag = mag
targetplayer = players[i]
end
end
end
end
end
end -- end of for loop
local stringscreen = math.random(1,3)
if stringscreen == 1 then
game.ReplicatedStorage.GUIEvent:FireClient(player)
end
if stringscreen == 2 then
game.ReplicatedStorage.GUIEvent:FireClient(player)
end
if stringscreen == 3 then
game.ReplicatedStorage.GUIEvent:FireClient(player)
end
--==========================
Local Script :
player = game.Players.LocalPlayer
game.ReplicatedStorage.GUIEvent.OnClientEvent:Connect(function(one)
local one = script.Parent.String1:Clone()
one.Parent = player.PlayerGui
wait(7.5)
one:Destroy()
script:Destroy()
end)
game.ReplicatedStorage.GUIEvent.OnClientEvent:Connect(function(two)
local two = script.Parent.String2:Clone()
two.Parent = player.PlayerGui
wait(7.5)
two:Destroy()
script:Destroy()
end)
game.ReplicatedStorage.GUIEvent.OnClientEvent:Connect(function(three)
local three = script.Parent.String3:Clone()
three.Parent = player.PlayerGui
wait(7.5)
three:Destroy()
script:Destroy()
end)
Then you can’t get the player from a model of the boss?
script.Parent.Parent would be equal to the boss character?
Try this script I made:
repeat wait() until script.Parent
local targetfound = false
repeat wait() until script.Parent.Name ~= "ErrorSansAttacks"
local mag = 4000
game.Players.PlayerAdded:Connect(function(player)
--================TargetPosition========================
local players = game.Players:GetChildren()
local range = 300
local lastmag= 1000
local mTorso = script.Parent.Parent:FindFirstChild("Torso")
local mHum = script.Parent:FindFirstChild("Humanoid")
local targetplayer = nil--players[1]
for i=1,#players do
wait()
if players[i].Character then
local char = players[i].Character
if char:FindFirstChild("Torso") then
local Torso = char:FindFirstChild("Torso")
local mag = (Torso.Position - script.Parent.Torso.Position).magnitude
if mag<=range then
if char.Name ~= script.Parent.Parent then
if mag < lastmag then
mag = (Torso.Position - script.Parent.Torso.Position).magnitude
lastmag = mag
targetplayer = players[i]
end
end
end
end
end
end -- end of for loop
local stringscreen = math.random(1,3)
if stringscreen == 1 then
local one = script.String1:Clone()
one.Parent = player.PlayerGui
wait(7.5)
one:Destroy()
script:Destroy()
end
if stringscreen == 2 then
local two = script.String2:Clone()
two.Parent = player.PlayerGui
wait(7.5)
two:Destroy()
script:Destroy()
end
if stringscreen == 3 then
local three = script.String3:Clone()
three.Parent = player.PlayerGui
wait(7.5)
three:Destroy()
script:Destroy()
end
end)
--==========================