What do you want to achieve? For my script to work and not fail.
What is the issue? The code is not running at all, not even printing anything
What solutions have you tried so far? It seems nobody has made a topic about this.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local rs = game:GetService("ReplicatedStorage")
local chatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
game:GetService("Players").PlayerAdded:Connect(function(plr)
local speaker = chatService:GetSpeaker(plr.Name)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Parent = plr
print('why isnt this working')
canHurt.Value = false
end)
It’s located in ServerScriptService and is a server script.
The code doesn’t seem to be running…
No errors, it’s just not running.
You can easily fix this issue, just loop through the players and run code for each player:
local rs = game:GetService("ReplicatedStorage")
local chatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
game:GetService("Players").PlayerAdded:Connect(function(plr)
local speaker = chatService:GetSpeaker(plr.Name)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Parent = plr
print('why isnt this working')
canHurt.Value = false
end)
for _, player in ipairs(game.Players:GetPlayers()) do
local speaker = chatService:GetSpeaker(plr.Name)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Parent = plr
print('why isnt this working')
canHurt.Value = false
end
local rs = game:GetService("ReplicatedStorage")
local chatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
game:GetService("Players").PlayerAdded:Connect(function(plr)
local speaker = chatService:GetSpeaker(plr.Name)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Parent = plr
print('why isnt this working')
canHurt.Value = false
local cooldown = Instance.new("NumberValue")
cooldown.Name = "cooldown"
cooldown.Parent = plr
local mps = game:GetService("MarketplaceService")
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
cooldown.Value = 35
plr:WaitForChild("PlayerGui"):WaitForChild("guistuff"):WaitForChild("angry"):WaitForChild("cooldowntime").Text = "35 Second Cooldown"
else
cooldown.Value = 40
end
-- V.I.P
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
local char = plr.Character or plr.CharacterAdded:Wait()
rs:WaitForChild("VIP"):Clone().Parent = char:WaitForChild("Head")
speaker:SetExtraData("Tags",{{TagText = "👑V.I.P", TagColor = Color3.fromRGB(234, 255, 0)}})
char:WaitForChild("Humanoid").WalkSpeed = 36
end
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
game:GetService("ServerStorage"):WaitForChild("boombox"):Clone().Parent = plr:WaitForChild('Backpack')
end
end)
-- Services --
local ps = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local chatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
-- Variables --
local id = 0; -- Your id here
-- Functions --
function SetupPlayer(plr)
local speaker = chatService:GetSpeaker(plr.Name)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Parent = plr
print('why isnt this working')
canHurt.Value = false
local cooldown = Instance.new("NumberValue")
cooldown.Name = "cooldown"
cooldown.Parent = plr
local mps = game:GetService("MarketplaceService")
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
cooldown.Value = 35
plr:WaitForChild("PlayerGui"):WaitForChild("guistuff"):WaitForChild("angry"):WaitForChild("cooldowntime").Text = "35 Second Cooldown"
else
cooldown.Value = 40
end
-- V.I.P
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
local char = plr.Character or plr.CharacterAdded:Wait()
rs:WaitForChild("VIP"):Clone().Parent = char:WaitForChild("Head")
speaker:SetExtraData("Tags",{{TagText = "👑V.I.P", TagColor = Color3.fromRGB(234, 255, 0)}})
char:WaitForChild("Humanoid").WalkSpeed = 36
end
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
game:GetService("ServerStorage"):WaitForChild("boombox"):Clone().Parent = plr:WaitForChild('Backpack')
end
end;
-- Player Joins --
for _, plr in ipairs(ps:GetPlayers())do
SetupPlayer(plr);
end;
ps.PlayerAdded:Connect(SetupPlayer);
Its because you are waiting for something AND requiring something. This takes time, and by the time that it is done loading that stuff the player has joined and hasn’t gotten to the PlayerAdded event.
local rs = game:GetService("ReplicatedStorage")
local chatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
chatService.SpeakerAdded:Connect(function(speakerName)
local speaker = chatService:GetSpeaker(speakerName)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Parent = plr
print('why isnt this working')
canHurt.Value = false
local cooldown = Instance.new("NumberValue")
cooldown.Name = "cooldown"
cooldown.Parent = plr
local mps = game:GetService("MarketplaceService")
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
cooldown.Value = 35
plr:WaitForChild("PlayerGui"):WaitForChild("guistuff"):WaitForChild("angry"):WaitForChild("cooldowntime").Text = "35 Second Cooldown"
else
cooldown.Value = 40
end
-- V.I.P
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
local char = plr.Character or plr.CharacterAdded:Wait()
rs:WaitForChild("VIP"):Clone().Parent = char:WaitForChild("Head")
speaker:SetExtraData("Tags",{{TagText = "👑V.I.P", TagColor = Color3.fromRGB(234, 255, 0)}})
char:WaitForChild("Humanoid").WalkSpeed = 36
end
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
game:GetService("ServerStorage"):WaitForChild("boombox"):Clone().Parent = plr:WaitForChild('Backpack')
end
end)
Just have a function that is connected to the PlayerAdded event and runs for every player in the game as well:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local chatService = require(ServerScriptService.ChatServiceRunner.ChatService)
local function PlayerAdded(plr)
local speaker = chatService:GetSpeaker(plr.Name)
local canHurt = Instance.new("BoolValue")
canHurt.Name = "canHurt"
canHurt.Value = false
canHurt.Parent = plr
local cooldown = Instance.new("NumberValue")
cooldown.Name = "cooldown"
canHurt.Parent = plr
local mps = game:GetService("MarketplaceService")
if mps:UserOwnsGamePassAsync(plr.UserId, id) then
cooldown.Value = 35
plr.PlayerGui:WaitForChild("guistuff"):WaitForChild("angry"):WaitForChild("cooldowntime").Text = "35 Second Cooldown"
else
cooldown.Value = 40
end
-- V.I.P
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
local char = plr.Character or plr.CharacterAdded:Wait()
rs:WaitForChild("VIP"):Clone().Parent = char:WaitForChild("Head")
speaker:SetExtraData("Tags",{{TagText = "👑V.I.P", TagColor = Color3.fromRGB(234, 255, 0)}})
char:WaitForChild("Humanoid").WalkSpeed = 36
end
if mps:UserOwnsGamePassAsync(plr.UserId,id) then
game:GetService("ServerStorage"):WaitForChild("boombox"):Clone().Parent = plr:WaitForChild('Backpack')
end
end
Players.PlayerAdded:Connect(PlayerAdded)
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(PlayerAdded)(player)
end