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

passing a localscript variable into a server script through remote event ?

Asked by 2 years ago

so i have been trying to make a script that changes your trail colour (through remote event), however when i try to set the colour for the trail i get an error saying attemp to index nil with ImageColor3, i understand why it is happening, however i am unsure how to fix it, the code below is what i have so far.

my sever script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local event = ReplicatedStorage:WaitForChild("lightningcolor")

local function colour(player)

    player.Character.Head.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.Head.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.Head.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.Head.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.UpperTorso.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.UpperTorso.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.UpperTorso.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.UpperTorso.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.RightUpperLeg.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightUpperLeg.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightUpperLeg.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightUpperLeg.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.RightUpperArm.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightUpperArm.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightUpperArm.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightUpperArm.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.RightHand.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightHand.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightHand.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightHand.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.RightFoot.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightFoot.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightFoot.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.RightFoot.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.LeftUpperLeg.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftUpperLeg.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftUpperLeg.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftUpperLeg.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.LeftUpperArm.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftUpperArm.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftUpperArm.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftUpperArm.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.LeftHand.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftHand.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftHand.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftHand.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

    player.Character.LeftFoot.trailOuter.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftFoot.trailInner.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftFoot.trailLight.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)
    player.Character.LeftFoot.lightningParticle.Color = ColorSequence.new(_G.colourDisplay.ImageColor3)

end

event.OnServerEvent:Connect(colour)

MY localScript

local colourWheel = script.Parent:WaitForChild("ColourWheel")
local wheelPicker = colourWheel:WaitForChild("Picker")

local darknessPicker = script.Parent:WaitForChild("DarknessPicker")
local darknessSlider = darknessPicker:WaitForChild("Slider")
_G.colourDisplay = script.Parent:WaitForChild("ColourDisplay")

local replicatedstorage = game:GetService("ReplicatedStorage")
local event  = replicatedstorage:WaitForChild("lightningcolor")
local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local buttonDown = false
local movingSlider = false


local function updateColour(centreOfWheel)


    local colourPickerCentre = Vector2.new(
        colourWheel.Picker.AbsolutePosition.X + (colourWheel.Picker.AbsoluteSize.X/2),
        colourWheel.Picker.AbsolutePosition.Y + (colourWheel.Picker.AbsoluteSize.Y/2)
    )
    local h = (math.pi - math.atan2(colourPickerCentre.Y - centreOfWheel.Y, colourPickerCentre.X - centreOfWheel.X)) / (math.pi * 2)

    local s = (centreOfWheel - colourPickerCentre).Magnitude / (colourWheel.AbsoluteSize.X/2)

    local v = math.abs((darknessSlider.AbsolutePosition.Y - darknessPicker.AbsolutePosition.Y) / darknessPicker.AbsoluteSize.Y - 1)


    _G.hsv = Color3.fromHSV(math.clamp(h, 0, 1), math.clamp(s, 0, 1), math.clamp(v, 0, 1))


    _G.colourDisplay.ImageColor3 = _G.hsv
    darknessPicker.UIGradient.Color = ColorSequence.new{
        ColorSequenceKeypoint.new(0, _G.hsv), 
        ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
    }
    event:FireServer()



end


colourWheel.MouseButton1Down:Connect(function()
    buttonDown = true
end)

darknessPicker.MouseButton1Down:Connect(function()
    movingSlider = true
end)


uis.InputEnded:Connect(function(input)

    if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end

    buttonDown = false
    movingSlider = false
    _G.colourDisplay.Visible = false
end)


uis.InputChanged:Connect(function(input)

    if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end


    local mousePos = uis:GetMouseLocation() - Vector2.new(0, game:GetService("GuiService"):GetGuiInset().Y)

    local centreOfWheel = Vector2.new(colourWheel.AbsolutePosition.X + (colourWheel.AbsoluteSize.X/2), colourWheel.AbsolutePosition.Y + (colourWheel.AbsoluteSize.Y/2))

    local distanceFromWheel = (mousePos - centreOfWheel).Magnitude


    if distanceFromWheel <= colourWheel.AbsoluteSize.X/2 and buttonDown then

        wheelPicker.Position = UDim2.new(0, mousePos.X - colourWheel.AbsolutePosition.X, 0, mousePos.Y - colourWheel.AbsolutePosition.Y)
        _G.colourDisplay.Visible = true
        _G.colourDisplay.Position = UDim2.new(0.750, mousePos.X - colourWheel.AbsolutePosition.X, -0.02, mousePos.Y - colourWheel.AbsolutePosition.Y )


    elseif movingSlider then

        darknessSlider.Position = UDim2.new(darknessSlider.Position.X.Scale, 0, 0, 
            math.clamp(
            mousePos.Y - darknessPicker.AbsolutePosition.Y, 
            0, 
            darknessPicker.AbsoluteSize.Y)
        )   
    end


    updateColour(centreOfWheel)
end)

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Hi gamer!

I think your problem here is that you're changing the value on the client. When you change a value from the client, the server doesn't notice the change and do nothing because the change as been made locally and not by the server.

What you could do is, you could move your updateColour function to a server-sided script and use a remote event to communicate.

You could also use a remote function;

— Fire the function from the server to the client and return the color value, however i don't think you shouldn't do that this way because you should NEVER trust the client.

Remote Function and Event here! Click me :)

0
That is incorrect. The person already has a remote event. Remote events are used to communicate from server to client vice-versa. JesseSong 3916 — 2y
0
hello thankyou for your reply, i fixed it , it was just a spelling error :D gymsharklife1 54 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

hello thankyou for your reply, i fixed it , it was just a spelling error :D

Answer this question