Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this work Filering enabled script work??? i changed it to a script

Asked by 5 years ago

so i tried to FE this script

local player = game:GetService("Players").LocalPlayer
local button = script.Parent 

button.Activated:Connect(function()
    local char = player.Character

   char.EyeColor.BrickColor = BrickColor.new(script.Parent.Color.Value)
end)


and it turned out like this but the new code wont work... why??? | v

local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local button = script.Parent 

button.Activated:Connect(function()
    local char = player.Character

   char.ChestColor1.BrickColor = BrickColor.new(script.Parent.Color.Value)
end)


0
It depends on a lot of factors right now. First, what is the button, and second, what type of script is this. Well only 2 but still. namespace25 594 — 5y
0
Please read up on the Remote Events/Functions tutorial https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events Shawnyg 4330 — 5y
0
Your first script was fine. The second script had issues. Your problem is that you need to only use LocalPlayer with local scripts, thus requiring you to use Remote Events and/or Remote Functions RBLXNogin 187 — 5y

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

I suggest you should read up on RemoteEvents, just because you change a LocalScript to Server, doesn't mean it will always work. I will provide links at the end.

Setting up:

  1. Create a RemoteEvent, place it within' ReplicatedStorage. Name it what you wish.
  2. Place a LocalScript within' the button (assuming it's a Text/Image Button).
  3. Place a ServerScript within' ServerScriptService.

Understanding FilterEnabled:

FilteringEnabled is a way to prevent exploiters replicating their client onto the server without the use of Events. Do keep in mind, as enabling it may prevent exploiters, it will also prevent any client replicating over, meaning you have to send information from Client to Server if you wish to replicate things through.

Understanding RemoteEvents: There are a lot of events in which can help you replicate over to server, but most common being RemoteEvents. Here you can send information from Client to Server to allow things to replicate over.

The fault in your code: You have tried using a ServerScript to activate something which is on the Client, this will not work and has to be through the client. This means will we have to use RemoteEvents to fire information over.

New code, explained:

Assuming you've done the setting up correctly, you can now start to place in your code.

LocalScript


local RS = game:GetService('ReplicatedStorage') local Player = game.Players.LocalPlayer local Button = script.Parent local ColorValue = Button:WaitForChild('Color') Button.MouseButton1Down:Connect(function() RS:WaitForChild('RemoteEvent'):FireServer(ColorValue.Value) -- WaitForChild prevents it from causing errors if you click the button before the remote is loaded in, but this will happen rarely but just incase. FireServer fires the remote to server, just like it implies. You are sending over your color value data. end)

ServerScript

local RS = game:GetService('ReplicatedStorage')
local Remote = RS:WaitForChild('RemoteEvent')

Remote.OnServerEvent = function(Player, ColorValue) -- Player is automatically fired over, the second parameter being your colorvalue you sent over
    local Character = Player.Character or Player.CharacterAdded:Wait() -- Find character or wait for it to load in.
    Character.ChestColor1.BrickColor = BrickColor.new(ColorValue) -- change the color
end -- Finally, ending the function.

Summary:

You can learn more about RemoteEvents by clicking on the word link.

If you are still stuck or get any errors please feel free to add my Discord: Josh K#2740

0
thanks! im stuck on a part and i can't friend you on discord... the tag wont work Deinonychusaurus 21 — 4y
0
its errors with this btw "OnServerEvent is not a valid member of RemoteEvent" Deinonychusaurus 21 — 4y
0
Try Josh K#0001 pwx 1581 — 4y
0
ok sent!! im pigeon Deinonychusaurus 21 — 4y
Ad

Answer this question