Hey guys! I have a script that makes a player drop their candy in this Halloween game I am making. Problem is, it doesnt work on Filtering Enabled servers. Im very new to Filtering Enabled, so if someone could tell me what to do, that'd be great! Thank you!
Here is my script
wait(.5) --Very inefficient but whatever aaa script.Parent = script.Parent.Humanoid local playeer = script.Parent.Parent.Name local player = game.Players[playeer] -------------------------------------------------------------------------------- --Put in startercharacter script.Parent.Died:connect(function() local i = math.random(1,10) if (player.leaderstats.Candy.Value - i) < 0 then i = player.leaderstats.Candy.Value end player.leaderstats.Candy.Value = player.leaderstats.Candy.Value - i -------------------------------------------------------------------------- if i ~= 0 then repeat i = i - 1 local position = script.Parent.Parent.Torso.CFrame*CFrame.new(math.random(-4,4),8,math.random(-4,4)) local Candy = game.ServerStorage.Candy:Clone() Candy:Clone() Candy.Parent = game.Workspace Candy.CFrame = position until i <= 0 ---------------------------------------------------- for i,v in pairs (script.Parent.Parent:GetChildren()) do if v:IsA("BasePart") or v:IsA("Accessory") then v:Destroy() end end end end)
In order for your script to function correctly, you would put it in ServerScriptStorage
and retrieve the player variable from a PlayerAdded
event.
game.Players.PlayerAdded:Connect(function(player) --PlayerAdded event player.CharacterAdded:Connect(function(char) --CharacterAdded event char:WaitForChild("Humanoid").Died:Connect(function() local i = math.random(1,10) if (player.leaderstats.Candy.Value - i) < 0 then i = player.leaderstats.Candy.Value end player.leaderstats.Candy.Value = player.leaderstats.Candy.Value - i if i ~= 0 then local tor = char:WaitForChild("Torso") local pos = tor.CFrame*CFrame.new(math.random(-4,4),8,math.random(-4,4)) repeat i = i - 1 local Candy = game.ServerStorage.Candy:Clone() Candy:Clone() Candy.Parent = game.Workspace Candy.CFrame = pos until i <= 0 for i,v in pairs (char:GetChildren()) do if v:IsA("BasePart") or v:IsA("Accessory") then v:Destroy() end end end end) end) end)