I’m about to start a show with my cousin in a WWE game, and I need to have it finished before the show starts. I am working on a script where if I have it where you can get Cleans automatically, it will give it to the player, and remove it from the player when it’s disabled.
I just tried testing it and checked if there was any issues that was in my code, and I can’t seem to find anything that could make it not work.
Could anyone help me debug it so it can work?
Here is the script inside the server, since it does work Locally by using print(data).
--// Variables
local Players = game:GetService("Players")
local Remotes = game:GetService("ReplicatedStorage").Remotes
local CleansAllowedCheck = Remotes.CleansAllowed
local Gears = game:GetService("ReplicatedStorage").Gears
local Clean = Gears.Clean:Clone()
--// Script
CleansAllowedCheck.OnServerEvent:Connect(function(player, data)
print(data)
if data == "Allowed" then
player.CharacterAdded:Connect(function(character)
local backpack = player:FindFirstChild("Backpack")
local CleanFound = backpack:FindFirstChild("Clean")
if not CleanFound then
Clean.Parent = backpack
end
end)
elseif data == "Denied" then
player.CharacterAdded:Connect(function(character)
local backpack = player:FindFirstChild("Backpack")
local CleanFound = backpack:FindFirstChild("Clean")
if CleanFound then
CleanFound:Destroy()
elseif not CleanFound then
print(`Player does not have a clean, so I can't remove anything!`)
end
end)
end
end)
The player’s character may have loaded in by the time the it gets to the player.CharacterAdded function, therefore the function doesn’t run. Try checking if the character has already loaded in.
local function giveClean(player)
local Backpack = player:FindFirstChild("Backpack")
if Backpack:FindFirstChild("Clean") then
Clean:Clone().Parent = Backpack
end
end
if data == "Allowed" then
if player.Character then
giveClean(player)
end
player.CharacterAdded:Connect(function()
giveClean(player)
end
end
What is the result when you use print(data)? If it prints "Allowed", show us the code for the local script firing the remote event. The server seem fine, so it might be a problem on the client end.
Everything looks fine here, so I think we need to do print debugging. Try putting print statements after two of these lines, and tell me if they print: