How do I acces my part and change its positions and stuff I send the variable from a server script through a remote event to a local script but then if I try to acces its position its nil
local buttonSize = stepPart.Position.X / equipped
How do I acces my part and change its positions and stuff I send the variable from a server script through a remote event to a local script but then if I try to acces its position its nil
local buttonSize = stepPart.Position.X / equipped
Could we have more information? Show us the line where the RemoteEvent is fired and the line where it’s received.
server script:
local boxBought = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("BoxBoughtRemoteEvent")
local openBox = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("OpenBoxRemoteEvent")
local checkAutoDelete = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("CheckAutoDeleteRemoteEvent")
local backToServerAutoDelete = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("BackToServerAutoDeleteRemoteEvent")
local debounce = false
local buttonModule = require(game:GetService("ServerScriptService"):WaitForChild("ModuleScripts"):WaitForChild("ButtonModuleScript"))
boxBought.OnServerEvent:Connect(function(player, boxName, price)
if player.leaderstats.Money.Value >= price then
player.leaderstats.Money.Value -= price
local button = buttonModule.ChooseRandomButton(boxName)
print(button)
checkAutoDelete:FireClient(player,button)
backToServerAutoDelete.OnServerEvent:Connect(function(player,autoDelete)
if debounce == false then
debounce = true
openBox:FireClient(player,button,boxName,autoDelete)
if autoDelete == false then
local newButton = Instance.new("StringValue")
newButton.Name = button
newButton.Value = button
newButton:SetAttribute("MoneyMultiplier",game:GetService("ReplicatedStorage").Boxes:FindFirstChild(boxName):FindFirstChild(button):GetAttribute("MoneyMultiplier"))
newButton:SetAttribute("Equip",false)
newButton.Parent = player.ButtonInventory
end
wait(5)
debounce = false
end
end)
end
end)
local script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local sendEquipToButton = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("SendEquipToButtonRemoteEvent")
local player = game.Players.LocalPlayer
sendEquipToButton.OnClientEvent:Connect(function(buttonName,equip,stepPart)
if equip == true then
local eqquipedButtonsTable = {}
local equipped = 0
for i,v in pairs(player.ButtonInventory:GetChildren()) do
if v:GetAttribute("Equip") == true then
equipped += 1
end
end
print(equipped)
local buttonSize = stepPart.Position.X / equipped
local maxEquip = player.Values.MaxEquip.Value
local posNumber = 1
for i,v in pairs(player.ButtonInventory:GetChildren()) do
if v:GetAttribute("Equip") == true then
local equipButtonName = v.Name
table.insert(eqquipedButtonsTable, equipButtonName)
end
end
repeat
local randomButton = table[math.random(1, #eqquipedButtonsTable)]
table.remove(eqquipedButtonsTable,randomButton)
local newButton = stepPart:Clone()
newButton.Name = randomButton
newButton.Size = Vector3.new(buttonSize, newButton.Size.Y, newButton.Size.Z)
newButton.Position = Vector3.new(stepPart.Position.X - 0.5 * posNumber, newButton.Position.Y, newButton.Position.Z)
newButton.Transparency = 0
newButton.Parent = stepPart.Parent
posNumber += 1
until posNumber >= maxEquip
elseif equip == false then
end
end)
Make sure the part exists on both the server side and the client side.
Nowhere in the server script does it fire the SendEquipToButtonRemoteEvent
RemoteEvent, which is the one received by the localscript. Are you sure this is the correct script?
wrong script sorry
local replicatedStorage = game:GetService("ReplicatedStorage")
local sendEquip = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("SendEquipRemoteEvent")
local sendEquipToButton = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("SendEquipToButtonRemoteEvent")
local stepPart = game:GetService("Workspace"):WaitForChild("Map"):WaitForChild("StepPartModel"):WaitForChild("StepPart")
sendEquip.OnServerEvent:Connect(function(player,buttonName,equip)
if equip == true then
local maxEquip = player.Values.MaxEquip.Value
local equipped = 0
for i,v in pairs(player.ButtonInventory:GetChildren()) do
if v:GetAttribute("Equip") == true then
equipped += 1
end
end
if equipped < maxEquip then
if player.ButtonInventory:FindFirstChild(buttonName) then
player.ButtonInventory:FindFirstChild(buttonName):SetAttribute("Equip",true)
sendEquipToButton:FireClient(player,buttonName,equip,stepPart)
end
end
elseif equip == false then
end
end)
does something error or yield in the output? Make sure the path to stepPart
is correct.
Also make sure all the arguments in the functions are correct. Try printing out every argument and see what comes out. If you’re expecting a string and get a bool for example, you know there’s something wrong.
its correct and it does yield_
oh then could you screenshot the output?
Maybe try passing the Position of “StepPart” to the client, instead of the Instance.
Server Script:
-- Your existing code...
sendEquip.OnServerEvent:Connect(function(player, buttonName, equip)
if equip == true then
-- Your existing code...
if equipped < maxEquip then
if player.ButtonInventory:FindFirstChild(buttonName) then
player.ButtonInventory:FindFirstChild(buttonName):SetAttribute("Equip", true)
-- Instead of sending stepPart, send its position
local stepPartPosition = stepPart.Position
sendEquipToButton:FireClient(player, buttonName, equip, stepPartPosition)
end
end
elseif equip == false then
-- Your existing code...
end
end)
Local Script:
-- Your existing code...
sendEquipToButton.OnClientEvent:Connect(function(buttonName, equip, stepPartPosition)
if equip == true then
-- Your existing code...
local buttonSize = stepPartPosition.X / equipped
-- Rest of your existing code...
elseif equip == false then
-- Your existing code...
end
end)
can I then still cahnge the position of the part and so only the player sees it
Honestly, why don’t you just access the StepPart directly in the localScript instead of firing it from server to client? Can’t you just write the following in the local script and remove “stepPart” from the RemoteEvent?
I tried that but thats qhy I made this post
if “stepPart” was a cloned part that you only wanted the player to be able to see the position change, then yes it would make more sense to fire it thru a remote to the client, but here I don’t see why it’s needed as the part already exists when the game loads. Make sure there aren’t multiple variables with the name “stepPart”.
Its just there is a part in the workspace adn if I clone it it only clones for that player and if I change the clones position or size or whatever it will only change for that player, I hope what you jsut said works but I gotta go i’ll put it as solved tomorrow when I can test it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.