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

Why does it clone the StringValue into all players?

Asked by
MAKKU 37
4 years ago

So i want players to be able to claim a brick once when they click it. Currently instead of cloning a string value to the player that clicked the brick it gives clones to all players

--script

local ReplicatedStorage = game.ReplicatedStorage
local event = ReplicatedStorage.RemotEvent
bricks = game.Workspace.bricks



event.OnServerEvent:Connect(function(plr)
    for i,clickedbrick in pairs(bricks:GetChildren()) do
    for i,detector in pairs(clickedbrick:GetChildren()) do
    detector.MouseClick:Connect(function()

        if plr.questFolder:FindFirstChild(clickedbrick.Name) then
        print("Already claimed")
    else
        local cb = Instance.new("StringValue")
        cb.Parent = plr.questFolder
        cb.Value = clickedbrick.Name
        cb.Name = clickedbrick.Name

                end 
            end)
        end
    end
end)

--localscript

local ReplicatedStorage = game.ReplicatedStorage
local event = ReplicatedStorage.RemotEvent

game.Workspace.Baseplate.ClickDetector.MouseClick:Connect(function()
    event:FireServer()  
end)

1 answer

Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
4 years ago

I don't know why, you have it fire when you click another part...Anyways, it seems like that was your issue.

Try this, in your local script:


local ReplicatedStorage = game.ReplicatedStorage local event = ReplicatedStorage.RemotEvent local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() mouse.Button1Down:Connect(function() event:FireServer(plr) end)
Ad

Answer this question