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

Cant figure out how to get my placement script to figure out who owns which plot?

Asked by 5 years ago

So recently i got a placement system set up for my game and it works fine the only problem is i cant figure out how to get the script to figure out which player owns which plot and then only modify that plot. I tried to use remote events to communicate between the placement and the buyplot script but that didnt work at all.

--//Placement Script

local placementHandler = require(script:WaitForChild("PlacementModule"))
local base1 = workspace.Base1
local base2 = workspace.Base2
local base3 = workspace.Base3
local base4 = workspace.Base4
local items = game:GetService("ReplicatedStorage").Items
local plane = placementHandler.new(base4.Baseplate, base4.ItemHolder, 3)



local ItemOfChoice = "Model1"
local dummyModel 
local signal
local currentItemName
local function cancelPlacement()
    if (dummyModel) then
        plane:disable()
        if (dummyModel.Parent) then
            dummyModel:Destroy()
        end
        dummyModel:Destroy()
        dummyModel = nil
        signal = nil
        currentItemName = nil
    end
end
local function initiatePlacement(itemName)
    cancelPlacement()
    dummyModel = items[itemName]:clone()

    currentItemName = itemName

    for _, object in pairs(dummyModel:GetChildren()) do
        if(object:IsA("BasePart")) then
            object.CanCollide = false
        end
    end
    dummyModel.Parent = workspace

    local signal = plane:enable(dummyModel)


    signal:connect(function(location, model)
        game:GetService("ReplicatedStorage").ClientPlaced:FireServer(currentItemName, location)

        cancelPlacement()
    end)
end
wait(3)

initiatePlacement(ItemOfChoice)








BuyPlotScript

local plot = game.Workspace.Base4
local taken = false
local Owner = plot.Owner.Value
if Owner=="" then
    taken = false
else
    taken = true
end

script.Parent.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
    local player = game.Players:FindFirstChild(hit.Parent.Name)
    if taken==true or game.Workspace.Base1.Owner.Value==player.name or game.Workspace.Base2.Owner.Value==player.name
    or game.Workspace.Base3.Owner.Value==player.name or game.Workspace.Base4.Owner.Value==player.name then
        print("You already own a plot or the current plot is already owned!")
    else
        game.Workspace.Base4.Owner.Value = player.name
        print(game.Workspace.Base4.Owner.Value)
        script.Parent.Parent:Destroy()
        taken= true
    end
    end
end)

Placement Server Side Script

local items = game:GetService("ReplicatedStorage").Items
game:GetService("ReplicatedStorage").ClientPlaced.OnServerEvent:connect(function(player, itemName, location)
    local itemTemplate = items:FindFirstChild(itemName)
    if (itemTemplate) then
        local item = itemTemplate:clone()
        item.Parent = workspace.Base.ItemHolder
        item:SetPrimaryPartCFrame(location[1])
    end
end)

If you guys could help me out on this problem it would mean alot to me Thanks!

0
wait am i wrong or did you ask this question earlier / the other day? SerpentineKing 3885 — 5y
0
He has asked it before, its been some time though. DinozCreates 1070 — 5y
0
Looks like it was deleted DinozCreates 1070 — 5y
0
Why does your if statement have like 50 conditions. Your code needs to be restructured immediately. User#24403 69 — 5y
View all comments (3 more)
0
From lines 4 to 8, assuming the BuyPlotScript runs when the server begins, that segment will never change the value of "taken" to true. Unless you're disabling and re-enabling the script, try putting it in a loop SerpentineKing 3885 — 5y
0
You should index the model with the player that joined or something seith14 206 — 5y
0
@incapaxx, there aren't that many conditions in the code given to us (7) SerpentineKing 3885 — 5y

Answer this question