2
votes

I am making a placing system (it is basic so far) but it is not placing anything. the code works up until the 'while whenclicked = true' part, here's the code:

print('works')
while true do
    print('works2')
    local ImportedValueX = game.ReplicatedStorage.ActPosX
    local ImportedValueY = game.ReplicatedStorage.ActPosY
    local ImportedValueZ = game.ReplicatedStorage.ActPosZ
    local Block = game.ReplicatedStorage.Experimental
    local WhenClicked = game.ReplicatedStorage.WhenClicked.Value
    print('works3')
    while WhenClicked == true do
        print('wore')
        PlacedBlock = Block:Clone()
        PlacedBlock.Parent = workspace
        PlacedBlock.Position.X = ImportedValueX
        PlacedBlock.Position.Y = ImportedValueY
        PlacedBlock.Position.Z = ImportedValueZ
        WhenClicked = false
        wait(1)
    end
    wait(0.1)
end

The variables work fine and the whenclick part also works, i think the while whenclicked part is broken.

1

1 Answers

1
votes

I see a problem here:

PlacedBlock.Position.X = ImportedValueX
PlacedBlock.Position.Y = ImportedValueY
PlacedBlock.Position.Z = ImportedValueZ

The X, Y, Z are read-only properties. You need to populate them by creating a new Vector3 object and assigning it to the Position property, like this:

PlacedBlock.Position = Vector3.new(ImportedValueX, ImportedValueY, ImportedValueZ)

Updated:

I am making the assumption that you are trying to use replicate storage to signal the mouse click state (whenClicked) from your client to the server. The server then checks on the state as well as the x/y/z position in a loop. This is not working, because ReplicatedStorage does not replicate your values to the server. That would probably be an opening for exploits otherwise. So, in order to signal something from your client to your server you should use RemoteEvent or RemoteFunction (look those up in the reference manual). In your case, your server script could look something like this:

local event = Instance.new("RemoteEvent", game.ReplicatedStorage)
event.Name = "MyRemoteEvent"

local Block = game.ReplicatedStorage.Experimental

event.OnServerEvent:Connect(function(plr, position, whenClicked)
    if whenClicked then
        print('wore')
        local placedBlock = Block:Clone()
        placedBlock.Parent = workspace
        placedBlock.Position = position
    end
end)

So this would create a remote event in ReplicatedStorage and then listen to it. When it is called from the client, it will then do what you wanted to do (clone the part and position it).

In your client script you would trigger the event like this:

-- wait until the server has created the remote event
local event = game.ReplicatedStorage:WaitForChild("MyRemoteEvent")

-- do whatever you need to do, then call trigger the event:
event:FireServer(Vector3.new(5,5,5), true)