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

Why is this basic mouse-held decal animation not working online?

Asked by 9 years ago

I've been developing a simple mechanism using decals and implementing them on Part surfaces. In general, I've been getting it to work in the test environment, but for some reason, could not figure out why it would not work online. My approach for this problem is to create a script within the object that will then delete the decal in a timely/ orderly fashion, and a local script would be used to create it on a mouse clicked event. The following is the code that includes the decal installation:

-- brick destroy; this is an attempt to detect mouse hold; this works, but want simpler code though
local vb= 0--extra variable for testing purposes
ResetValue= function(Self)
    holdVal= 0
    textLabelHoldMouse.Text= "Hold: "..holdVal
end

Mouse.Button1Down:connect(function()    
    if workspace.numMode.Value== 0 and tostring(Mouse.Target)== "DirtBlockClone" and Player:DistanceFromCharacter(Mouse.Target.Position)< 16 and workspace.inventoryHold.Value< invMax then
        Mouse.Button1Up:connect(function()--inside button down so holdVal can recount if pos changes
            holdSwitch= 1
            ResetValue()
        end)

        holdSwitch= 0
        while holdSwitch== 0 do
            local target= tostring(Mouse.Target.Position)
            wait(0)
            holdVal= holdVal+1
            textLabelHoldMouse.Text= "Hold: "..holdVal
            if not Mouse.Target then--first checks if a target exists; ex., mouse hit air returns nil
                return
            elseif Player:DistanceFromCharacter(Mouse.Target.Position)>= 16 or target~= tostring(Mouse.Target.Position) then
                --target does exist, so do this
                ResetValue()
            end         

            if holdVal== 7 then--creating multiple decal clones causes more lag, so '==' is needed

                --local breaking1Group= Instance.new("Model",Mouse.Target.Parent)
                local breaking1Top= Instance.new("Decal",Mouse.Target)
                local breaking1Bottom= Instance.new("Decal",Mouse.Target)
                local breaking1Front= Instance.new("Decal",Mouse.Target)
                local breaking1Back= Instance.new("Decal",Mouse.Target)
                local breaking1Left= Instance.new("Decal",Mouse.Target)
                local breaking1Right= Instance.new("Decal",Mouse.Target)
                local breaking1remove= workspace.AnimationControl:Clone()
                --local breaking1remove= workspace.AnimationControlLocal:Clone()
                --local breaking1remove=    game.Players.LocalPlayer.PlayerGui.AnimationControlLocal.Disabled= false    

                breaking1Top.Texture= workspace.GraphicsGroup.Breaking1.Breaking1.Texture
                breaking1Top.Face= "Top"
                breaking1Bottom.Texture= workspace.GraphicsGroup.Breaking1.Breaking1.Texture
                breaking1Bottom.Face= "Bottom"
                breaking1Front.Texture= workspace.GraphicsGroup.Breaking1.Breaking1.Texture
                breaking1Front.Face= "Front"
                breaking1Back.Texture= workspace.GraphicsGroup.Breaking1.Breaking1.Texture
                breaking1Back.Face= "Back"
                breaking1Left.Texture= workspace.GraphicsGroup.Breaking1.Breaking1.Texture
                breaking1Left.Face= "Left"
                breaking1Right.Texture= workspace.GraphicsGroup.Breaking1.Breaking1.Texture
                breaking1Right.Face= "Right"
                breaking1remove.Parent= Mouse.Target
                --breaking1remove.Disabled= false--by default script is disabled, so enable it when instantiated in DirtBlockClone object       
                --game.Players.LocalPlayer.PlayerGui.AnimationControlLocal.Disabled= false

            end

            if holdVal== 14 then

                local breaking2Top= Instance.new("Decal",Mouse.Target)
                local breaking2Bottom= Instance.new("Decal",Mouse.Target)
                local breaking2Front= Instance.new("Decal",Mouse.Target)
                local breaking2Back= Instance.new("Decal",Mouse.Target)
                local breaking2Left= Instance.new("Decal",Mouse.Target)
                local breaking2Right= Instance.new("Decal",Mouse.Target)

                breaking2Top.Texture= workspace.GraphicsGroup.Breaking2.Breaking2.Texture
                breaking2Top.Face= "Top"
                breaking2Bottom.Texture= workspace.GraphicsGroup.Breaking2.Breaking2.Texture
                breaking2Bottom.Face= "Bottom"
                breaking2Front.Texture= workspace.GraphicsGroup.Breaking2.Breaking2.Texture
                breaking2Front.Face= "Front"
                breaking2Back.Texture= workspace.GraphicsGroup.Breaking2.Breaking2.Texture
                breaking2Back.Face= "Back"
                breaking2Left.Texture= workspace.GraphicsGroup.Breaking2.Breaking2.Texture
                breaking2Left.Face= "Left"
                breaking2Right.Texture= workspace.GraphicsGroup.Breaking2.Breaking2.Texture
                breaking2Right.Face= "Right"

            end
            if holdVal> 21 then
                ResetValue()
                Mouse.Target:Destroy()
                game.Players.LocalPlayer.PlayerGui.SoundDig:Play()
                workspace.inventoryHold.Value= workspace.inventoryHold.Value+1
                textLabelInv.Text= "Inventory: "..workspace.inventoryHold.Value.."/"..invMax                
            end
        end 
    end
end)

The following is the inserted script into the Part of interest that is called from the script above:

while true do
wait(0.5)
if tostring(script.Parent)== "DirtBlockClone" then
    script.Parent:ClearAllChildren()
end
end

To sum it up: local breaking1remove= workspace.AnimationControl:Clone() clones a pre-made script (the while true do block) and then it is inserted into a clone of DirtBlock, DirtBlockClone. The Mouse.Target is also the 'DirtBlockClone', so** the Decals are in the same hierarchy as the 2nd script**. That is why script.Parent:ClearAllChildren()is used to delete all children of the 'DirtBlockClone' of interest, which means that it deletes all Decals that appears on all the sides (a perfect cube) and the small script itself, in a timely fashion. I decided against using a wait function because it would pause the script and would therefore lead to my holdVal value to pause as well. I wanted to choose something where the main script would not pause, but only the decal to hold from being destroyed after being instantiated.

Another thing was that there were no errors spawned during the development so far, so I have a speculation for another possibility that it may have something to do with local and server-side runs, or the ClearAllChildren() event I have been using.

Edit: As the player holds down the mouse at the target, holdVal increases by a step of wait(0). Once it hits 7 the first set of 6 decals is instantiated. Once it hits 14, the second set is placed on all sides. So basically, in online play the 2nd script isn't functioning, meaning if you held down the button between 7 and 14, or 14 to 21, the decals will stay even if you move your mouse away from the target, unless you hold down the mouse at the target past 21 which destroys the brick and decals. In the test environment, holding down between these values (so doesn't matter what value before holdVal=22 or more is reached), the decals will delete after 0.5 seconds, which works independently from the main script.

0
What is it not doing online that it is supposed to do? 1waffle1 2908 — 9y
0
In the test environment, the player doing left mouse hold increases holdVal, and therefore adds a decal at each value until 21 or so; when held long enough without releasing the mouse or leaving the target, the brick is destroyed. Houlardy642 28 — 9y
0
Online, the decals are created as the player holds mouse down, but they do not delete, meaning that if partially held, the decals stay on the surfaces and are not removed, that is unless you hold long enough to destroy the block all together. Houlardy642 28 — 9y
0
Is FilteringEnabled on? That could potentially cause this sort of unexpected behavior. 1waffle1 2908 — 9y
0
For the Workspace? I have it set to true; so I should set it to false? Houlardy642 28 — 9y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

If FilteringEnabled is on then it means clients cannot make changes to the server. The problem that this causes for you here is that you're inserting a server-sided script into a server-sided object which you made client-sided changes to. You've added a bunch of decals into a part on the client, and then have the server delete them, but they don't exist on the server, they only exist for you because filtering is enabled.

If you turn off FilteringEnabled, then the client will be able to make changes to the server, but this is not recommended for developers creating new games for security reasons. It is better to have the client send signals to the server which will handle the mechanics rather than making changes from the client.

0
Hmm, thanks for your response; I'll have to find a way for the client to call the server, and then have the server remove the decals. Houlardy642 28 — 9y
Ad

Answer this question