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

Script not Starting,Won't Change properties when parent clicked?

Asked by 5 years ago
Edited 5 years ago

I don't know why; no errors are being produced. Here is my code:

print("Script Active!")
script.Parent.MouseButton1Click:connect(function()
    print("Button1 Clicked")
    workspace.PrisonCell.Door.Bar1.Anchored = false
    workspace.PrisonCell.Door.Bar2.Anchored = false
    workspace.PrisonCell.Door.Bar3.Anchored = false
    workspace.PrisonCell.Door.Bar4.Anchored = false
    workspace.PrisonCell.Door.Bar5.Anchored = false
    workspace.PrisonCell.Door.Bar6.Anchored = false
    workspace.PrisonCell.Door.Main.Disabled = true
end)

There are no errors, or things being printed. it is in a starter Gui and is a normal script(not local). Is It my code? Or Is it roblox(I have tried Mousebutton1Down That Doesn't Work) Let me know if you need more info.

1
well as you said its a server script so it wont work, it gotta be a local script starmaq 1290 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

This would work but it needs to be a local script rather than a server script. Also connect is deprecated, use Connect (capital C)

Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago
Edited 5 years ago

We live in FilteringEnabled times. That is client can not manipulate shared workspace, other than through moving his character, remote events and/or remote functions...

Change your script to localScript and edit like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PrisonCellOpenRequest = ReplicatedStorage:WaitForChild("PrisonCellOpenRequest")

print("Script Active!")
script.Parent.MouseButton1Click:Connect(function()
    print("Button1 Clicked")
    local result = PrisonCellOpenRequest:InvokeServer()
    print(result)
end)

Then add this script to a ServerScriptStorage:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PrisonCellOpenRequest = Instance.new("RemoteFunction")
PrisonCellOpenRequest.Parent = ReplicatedStorage
PrisonCellOpenRequest.Name = "PrisonCellOpenRequest"

local function onPrisonCellOpenRequest(player)

    --you can add checks here if player is allowed to open the cell door here
    workspace.PrisonCell.Door.Bar1.Anchored = false
    workspace.PrisonCell.Door.Bar2.Anchored = false
    workspace.PrisonCell.Door.Bar3.Anchored = false
    workspace.PrisonCell.Door.Bar4.Anchored = false
    workspace.PrisonCell.Door.Bar5.Anchored = false
    workspace.PrisonCell.Door.Bar6.Anchored = false
    workspace.PrisonCell.Door.Main.Disabled = true
    return "Success"

end

PrisonCellOpenRequest.OnServerInvoke = onPrisonCellOpenRequest


Edit: Changed connect to Connect

Answer this question