Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Heyo, I need some help making this script Filtering Enabled compatible! Please help!?

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)

1 comment

0

Think about it. Client changes do not get replicated to the server. RemoteEvents are for transferring data to client and server and server to client.

1 answer

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)

4 comments

0

Er, doesn't seem to work. It works in studio, but not in actual game. Am I forgetting something?

0

Lines 10 and 18 would be your problem.

0

The hierarchy to the Character object had changed.

0

fixed mate <3

This discussion is preserved as it was. New answers, comments, and votes are closed.